Skip to content

Commit 80c7df7

Browse files
chore: enforce the use of top-level import type
1 parent ff9756c commit 80c7df7

File tree

137 files changed

+402
-441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+402
-441
lines changed

.eslintrc.cjs

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ module.exports = {
4141
fixStyle: 'inline-type-imports',
4242
},
4343
],
44+
// Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers
45+
'@typescript-eslint/no-import-type-side-effects': 'error',
4446
},
4547
overrides: [
4648
// tests, no restrictions (runs in Node / jest with jsdom)

packages/compiler-core/__tests__/parse.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type ParserOptions } from '../src/options'
1+
import type { ParserOptions } from '../src/options'
22
import { baseParse, TextModes } from '../src/parse'
33
import { ErrorCodes } from '../src/errors'
44
import {

packages/compiler-core/__tests__/transforms/vModel.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { transformElement } from '../../src/transforms/transformElement'
1919
import { transformExpression } from '../../src/transforms/transformExpression'
2020
import { transformFor } from '../../src/transforms/vFor'
2121
import { trackSlotScopes } from '../../src/transforms/vSlot'
22-
import { type CallExpression } from '@babel/types'
22+
import type { CallExpression } from '@babel/types'
2323

2424
function parseWithVModel(template: string, options: CompilerOptions = {}) {
2525
const ast = parse(template)

packages/compiler-core/__tests__/utils.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { type TransformContext } from '../src'
2-
import { type Position } from '../src/ast'
1+
import type { TransformContext } from '../src'
2+
import type { Position } from '../src/ast'
33
import {
44
getInnerRange,
55
advancePositionWithClone,

packages/compiler-core/src/ast.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isString } from '@vue/shared'
2-
import { type ForParseResult } from './transforms/vFor'
2+
import type { ForParseResult } from './transforms/vFor'
33
import {
44
type RENDER_SLOT,
55
type CREATE_SLOTS,
@@ -13,8 +13,8 @@ import {
1313
CREATE_BLOCK,
1414
CREATE_ELEMENT_BLOCK,
1515
} from './runtimeHelpers'
16-
import { type PropsExpression } from './transforms/transformElement'
17-
import { type ImportItem, type TransformContext } from './transform'
16+
import type { PropsExpression } from './transforms/transformElement'
17+
import type { ImportItem, TransformContext } from './transform'
1818

1919
// Vue template is a platform-agnostic superset of HTML (syntax only).
2020
// More namespaces like SVG and MathML are declared by platform specific

packages/compiler-core/src/codegen.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type CodegenOptions } from './options'
1+
import type { CodegenOptions } from './options'
22
import {
33
type RootNode,
44
type TemplateChildNode,
@@ -54,7 +54,7 @@ import {
5454
WITH_CTX,
5555
RESOLVE_FILTER,
5656
} from './runtimeHelpers'
57-
import { type ImportItem } from './transform'
57+
import type { ImportItem } from './transform'
5858

5959
const PURE_ANNOTATION = `/*#__PURE__*/`
6060

packages/compiler-core/src/compat/compatConfig.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { type SourceLocation } from '../ast'
2-
import { type CompilerError } from '../errors'
3-
import { type ParserContext } from '../parse'
4-
import { type TransformContext } from '../transform'
1+
import type { SourceLocation } from '../ast'
2+
import type { CompilerError } from '../errors'
3+
import type { ParserContext } from '../parse'
4+
import type { TransformContext } from '../transform'
55

66
export type CompilerCompatConfig = Partial<
77
Record<CompilerDeprecationTypes, boolean | 'suppress-warning'>

packages/compiler-core/src/compat/transformFilter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
isCompatEnabled,
1212
warnDeprecation,
1313
} from './compatConfig'
14-
import { type NodeTransform, type TransformContext } from '../transform'
14+
import type { NodeTransform, TransformContext } from '../transform'
1515
import { toValidAssetId } from '../utils'
1616

1717
const validDivisionCharRE = /[\w).+\-_$\]]/

packages/compiler-core/src/compile.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { type CompilerOptions } from './options'
1+
import type { CompilerOptions } from './options'
22
import { baseParse } from './parse'
33
import {
44
transform,
55
type NodeTransform,
66
type DirectiveTransform,
77
} from './transform'
88
import { generate, type CodegenResult } from './codegen'
9-
import { type RootNode } from './ast'
9+
import type { RootNode } from './ast'
1010
import { isString, extend } from '@vue/shared'
1111
import { transformIf } from './transforms/vIf'
1212
import { transformFor } from './transforms/vFor'

packages/compiler-core/src/errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type SourceLocation } from './ast'
1+
import type { SourceLocation } from './ast'
22

33
export interface CompilerError extends SyntaxError {
44
code: number | string

packages/compiler-core/src/options.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import {
2-
type ElementNode,
3-
type Namespace,
4-
type TemplateChildNode,
5-
type ParentNode,
1+
import type {
2+
ElementNode,
3+
Namespace,
4+
TemplateChildNode,
5+
ParentNode,
66
} from './ast'
7-
import { type TextModes } from './parse'
8-
import { type CompilerError } from './errors'
9-
import {
10-
type NodeTransform,
11-
type DirectiveTransform,
12-
type TransformContext,
7+
import type { TextModes } from './parse'
8+
import type { CompilerError } from './errors'
9+
import type {
10+
NodeTransform,
11+
DirectiveTransform,
12+
TransformContext,
1313
} from './transform'
14-
import { type CompilerCompatOptions } from './compat/compatConfig'
15-
import { type ParserPlugin } from '@babel/parser'
14+
import type { CompilerCompatOptions } from './compat/compatConfig'
15+
import type { ParserPlugin } from '@babel/parser'
1616

1717
export interface ErrorHandlingOptions {
1818
onWarn?: (warning: CompilerError) => void

packages/compiler-core/src/parse.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type ErrorHandlingOptions, type ParserOptions } from './options'
1+
import type { ErrorHandlingOptions, ParserOptions } from './options'
22
import { NO, isArray, makeMap, extend } from '@vue/shared'
33
import {
44
ErrorCodes,

packages/compiler-core/src/transform.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type TransformOptions } from './options'
1+
import type { TransformOptions } from './options'
22
import {
33
type RootNode,
44
NodeTypes,
@@ -39,7 +39,7 @@ import {
3939
} from './runtimeHelpers'
4040
import { isVSlot } from './utils'
4141
import { hoistStatic, isSingleElementRoot } from './transforms/hoistStatic'
42-
import { type CompilerCompatOptions } from './compat/compatConfig'
42+
import type { CompilerCompatOptions } from './compat/compatConfig'
4343

4444
// There are two types of transforms:
4545
//

packages/compiler-core/src/transforms/hoistStatic.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
getVNodeBlockHelper,
1717
getVNodeHelper,
1818
} from '../ast'
19-
import { type TransformContext } from '../transform'
19+
import type { TransformContext } from '../transform'
2020
import { PatchFlags, isString, isSymbol, isArray } from '@vue/shared'
2121
import { isSlotOutlet } from '../utils'
2222
import {
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { type DirectiveTransform } from '../transform'
1+
import type { DirectiveTransform } from '../transform'
22

33
export const noopDirectiveTransform: DirectiveTransform = () => ({ props: [] })

packages/compiler-core/src/transforms/transformElement.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type NodeTransform, type TransformContext } from '../transform'
1+
import type { NodeTransform, TransformContext } from '../transform'
22
import {
33
NodeTypes,
44
ElementTypes,

packages/compiler-core/src/transforms/transformExpression.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// - This transform is only applied in non-browser builds because it relies on
88
// an additional JavaScript parser. In the browser, there is no source-map
99
// support and the code is wrapped in `with (this) { ... }`.
10-
import { type NodeTransform, type TransformContext } from '../transform'
10+
import type { NodeTransform, TransformContext } from '../transform'
1111
import {
1212
NodeTypes,
1313
createSimpleExpression,
@@ -32,7 +32,7 @@ import {
3232
genPropsAccessExp,
3333
} from '@vue/shared'
3434
import { createCompilerError, ErrorCodes } from '../errors'
35-
import { type Node, type Identifier } from '@babel/types'
35+
import type { Node, Identifier } from '@babel/types'
3636
import { validateBrowserExpression } from '../validateExpression'
3737
import { parse } from '@babel/parser'
3838
import { IS_REF, UNREF } from '../runtimeHelpers'

packages/compiler-core/src/transforms/transformSlotOutlet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type NodeTransform, type TransformContext } from '../transform'
1+
import type { NodeTransform, TransformContext } from '../transform'
22
import {
33
NodeTypes,
44
type CallExpression,

packages/compiler-core/src/transforms/transformText.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type NodeTransform } from '../transform'
1+
import type { NodeTransform } from '../transform'
22
import {
33
NodeTypes,
44
type CompoundExpressionNode,

packages/compiler-core/src/transforms/vBind.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type DirectiveTransform } from '../transform'
1+
import type { DirectiveTransform } from '../transform'
22
import {
33
createObjectProperty,
44
createSimpleExpression,

packages/compiler-core/src/transforms/vMemo.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type NodeTransform } from '../transform'
1+
import type { NodeTransform } from '../transform'
22
import { findDir } from '../utils'
33
import {
44
convertToBlock,

packages/compiler-core/src/transforms/vModel.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type DirectiveTransform } from '../transform'
1+
import type { DirectiveTransform } from '../transform'
22
import {
33
createSimpleExpression,
44
createObjectProperty,

packages/compiler-core/src/transforms/vOn.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
type DirectiveTransform,
3-
type DirectiveTransformResult,
4-
} from '../transform'
1+
import type { DirectiveTransform, DirectiveTransformResult } from '../transform'
52
import {
63
createCompoundExpression,
74
createObjectProperty,

packages/compiler-core/src/transforms/vOnce.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type NodeTransform } from '../transform'
1+
import type { NodeTransform } from '../transform'
22
import { findDir } from '../utils'
33
import { type ElementNode, type ForNode, type IfNode, NodeTypes } from '../ast'
44
import { SET_BLOCK_TRACKING } from '../runtimeHelpers'

packages/compiler-core/src/transforms/vSlot.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
createArrayExpression,
2222
type SlotsExpression,
2323
} from '../ast'
24-
import { type TransformContext, type NodeTransform } from '../transform'
24+
import type { TransformContext, NodeTransform } from '../transform'
2525
import { createCompilerError, ErrorCodes } from '../errors'
2626
import {
2727
findDir,

packages/compiler-core/src/utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
type BlockCodegenNode,
2626
type MemoExpression,
2727
} from './ast'
28-
import { type TransformContext } from './transform'
28+
import type { TransformContext } from './transform'
2929
import {
3030
MERGE_PROPS,
3131
TELEPORT,
@@ -38,9 +38,9 @@ import {
3838
WITH_MEMO,
3939
} from './runtimeHelpers'
4040
import { isString, isObject, hyphenate, extend, NOOP } from '@vue/shared'
41-
import { type PropsExpression } from './transforms/transformElement'
41+
import type { PropsExpression } from './transforms/transformElement'
4242
import { parseExpression } from '@babel/parser'
43-
import { type Expression } from '@babel/types'
43+
import type { Expression } from '@babel/types'
4444

4545
export const isStaticExp = (p: JSChildNode): p is SimpleExpressionNode =>
4646
p.type === NodeTypes.SIMPLE_EXPRESSION && p.isStatic

packages/compiler-core/src/validateExpression.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { type SimpleExpressionNode } from './ast'
2-
import { type TransformContext } from './transform'
1+
import type { SimpleExpressionNode } from './ast'
2+
import type { TransformContext } from './transform'
33
import { createCompilerError, ErrorCodes } from './errors'
44

55
// these keywords should not appear inside expressions, but operators like

packages/compiler-dom/src/decodeHtml.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type ParserOptions } from '@vue/compiler-core'
1+
import type { ParserOptions } from '@vue/compiler-core'
22
import namedCharacterReferences from './namedChars.json'
33

44
// lazy compute this to make this file tree-shakable for browser

packages/compiler-dom/src/transforms/vShow.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type DirectiveTransform } from '@vue/compiler-core'
1+
import type { DirectiveTransform } from '@vue/compiler-core'
22
import { createDOMCompilerError, DOMErrorCodes } from '../errors'
33
import { V_SHOW } from '../runtimeHelpers'
44

packages/compiler-sfc/__tests__/compileScript/definePropsDestructure.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BindingTypes } from '@vue/compiler-core'
2-
import { type SFCScriptCompileOptions } from '../../src'
2+
import type { SFCScriptCompileOptions } from '../../src'
33
import { compileSFCScript, assertCode } from '../utils'
44

55
describe('sfc reactive props destructure', () => {

packages/compiler-sfc/__tests__/compileScript/hoistStatic.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BindingTypes } from '@vue/compiler-core'
2-
import { type SFCScriptCompileOptions } from '../../src'
2+
import type { SFCScriptCompileOptions } from '../../src'
33
import { compileSFCScript, assertCode } from '../utils'
44

55
describe('sfc hoist static', () => {

packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Identifier } from '@babel/types'
1+
import type { Identifier } from '@babel/types'
22
import { type SFCScriptCompileOptions, parse } from '../../src'
33
import { ScriptCompileContext } from '../../src/script/context'
44
import {

packages/compiler-sfc/src/compileScript.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ import {
99
type SFCDescriptor,
1010
type SFCScriptBlock,
1111
} from './parse'
12-
import { type ParserPlugin } from '@babel/parser'
12+
import type { ParserPlugin } from '@babel/parser'
1313
import { generateCodeFrame } from '@vue/shared'
14-
import {
15-
type Node,
16-
type Declaration,
17-
type ObjectPattern,
18-
type ArrayPattern,
19-
type Identifier,
20-
type ExportSpecifier,
21-
type Statement,
22-
type CallExpression,
14+
import type {
15+
Node,
16+
Declaration,
17+
ObjectPattern,
18+
ArrayPattern,
19+
Identifier,
20+
ExportSpecifier,
21+
Statement,
22+
CallExpression,
2323
} from '@babel/types'
2424
import { walk } from 'estree-walker'
25-
import { type RawSourceMap } from 'source-map-js'
25+
import type { RawSourceMap } from 'source-map-js'
2626
import {
2727
processNormalScript,
2828
normalScriptDefaultVar,

packages/compiler-sfc/src/compileStyle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
type StylePreprocessorResults,
1414
type PreprocessLang,
1515
} from './style/preprocessors'
16-
import { type RawSourceMap } from 'source-map-js'
16+
import type { RawSourceMap } from 'source-map-js'
1717
import { cssVarsPlugin } from './style/cssVars'
1818
import postcssModules from 'postcss-modules'
1919

packages/compiler-sfc/src/compileTemplate.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {
2-
type CompilerOptions,
3-
type CodegenResult,
4-
type CompilerError,
5-
type NodeTransform,
6-
type ParserOptions,
7-
type RootNode,
1+
import type {
2+
CompilerOptions,
3+
CodegenResult,
4+
CompilerError,
5+
NodeTransform,
6+
ParserOptions,
7+
RootNode,
88
} from '@vue/compiler-core'
99
import {
1010
SourceMapConsumer,

packages/compiler-sfc/src/parse.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import {
88
} from '@vue/compiler-core'
99
import * as CompilerDOM from '@vue/compiler-dom'
1010
import { type RawSourceMap, SourceMapGenerator } from 'source-map-js'
11-
import { type TemplateCompiler } from './compileTemplate'
11+
import type { TemplateCompiler } from './compileTemplate'
1212
import { parseCssVars } from './style/cssVars'
1313
import { createCache } from './cache'
14-
import { type ImportBinding } from './compileScript'
14+
import type { ImportBinding } from './compileScript'
1515
import { isImportUsed } from './script/importUsageCheck'
16-
import { type Statement } from '@babel/types'
16+
import type { Statement } from '@babel/types'
1717

1818
export const DEFAULT_FILENAME = 'anonymous.vue'
1919

0 commit comments

Comments
 (0)