Skip to content

Commit

Permalink
enhance: upgrade eslint parser to dependent on eslint v9
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenQingchuan committed Oct 27, 2024
1 parent a2024ed commit 3559bad
Show file tree
Hide file tree
Showing 80 changed files with 1,219 additions and 1,052 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"changeset:main": "pnpm changeset version --ignore \"vue-vine-tsc\" --ignore \"@vue-vine/nuxt\" && git add ./packages/**/package.json"
},
"devDependencies": {
"@antfu/eslint-config": "^2.22.0",
"@antfu/eslint-config": "^3.8.0",
"@baiwusanyu/utils-log": "^1.0.15",
"@changesets/cli": "^2.27.7",
"@types/node": "^20.11.27",
Expand Down
61 changes: 31 additions & 30 deletions packages/compiler/src/analyze.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
import hashId from 'hash-sum'
import type { BindingTypes } from '@vue/compiler-dom'
import { walkIdentifiers } from '@vue/compiler-dom'
import {
isArrayExpression,
isArrayPattern,
isBlockStatement,
isBooleanLiteral,
isClassDeclaration,
isDeclaration,
isExportDefaultDeclaration,
isFunctionDeclaration,
isIdentifier,
isImportDefaultSpecifier,
isImportNamespaceSpecifier,
isImportSpecifier,
isObjectPattern,
isStringLiteral,
isTSMethodSignature,
isTSPropertySignature,
isTaggedTemplateExpression,
isTemplateLiteral,
isVariableDeclaration,
isVariableDeclarator,
} from '@babel/types'
import type {
ArrayPattern,
ArrowFunctionExpression,
Expand All @@ -41,7 +16,7 @@ import type {
VariableDeclaration,
VariableDeclarator,
} from '@babel/types'
import { DEFAULT_MODEL_MODIFIERS_NAME, SUPPORTED_STYLE_FILE_EXTS, VineBindingTypes } from './constants'
import type { BindingTypes } from '@vue/compiler-dom'
import type {
BabelFunctionNodeTypes,
Nil,
Expand All @@ -56,7 +31,30 @@ import type {
VineStyleValidArg,
VineUserImport,
} from './types'

import {
isArrayExpression,
isArrayPattern,
isBlockStatement,
isBooleanLiteral,
isClassDeclaration,
isDeclaration,
isExportDefaultDeclaration,
isFunctionDeclaration,
isIdentifier,
isImportDefaultSpecifier,
isImportNamespaceSpecifier,
isImportSpecifier,
isObjectPattern,
isStringLiteral,
isTaggedTemplateExpression,
isTemplateLiteral,
isTSMethodSignature,
isTSPropertySignature,
isVariableDeclaration,
isVariableDeclarator,
} from '@babel/types'
import { walkIdentifiers } from '@vue/compiler-dom'
import hashId from 'hash-sum'
import {
canNeverBeRef,
findVineTagTemplateStringReturn,
Expand All @@ -80,9 +78,11 @@ import {
isVineStyle,
tryInferExpressionTSType,
} from './babel-helpers/ast'

import { DEFAULT_MODEL_MODIFIERS_NAME, SUPPORTED_STYLE_FILE_EXTS, VineBindingTypes } from './constants'
import { vineErr, vineWarn } from './diagnostics'
import { parseCssVars } from './style/analyze-css-vars'
import { isImportUsed } from './template/importUsageCheck'
import { vineErr, vineWarn } from './diagnostics'
import { _breakableTraverse, exitTraverse } from './utils'

interface AnalyzeCtx {
Expand Down Expand Up @@ -719,7 +719,8 @@ const analyzeVineSlots: AnalyzeRunner = (
if (isTSPropertySignature(prop) && isIdentifier(prop.key)) {
const fnFirstParamType
= ((prop.typeAnnotation!.typeAnnotation as TSFunctionType | Nil)
?.parameters?.[0]?.typeAnnotation as TSTypeAnnotation)
?.parameters?.[0]
?.typeAnnotation as TSTypeAnnotation)
?.typeAnnotation as TSTypeLiteral

if (fnFirstParamType) {
Expand Down Expand Up @@ -979,7 +980,7 @@ function buildVineCompFnCtx(
isNeedLinkedCodeTag
? `${createLinkedCodeTag('left', propName.length)}${propName}`
: propName
}: ${propMeta.typeAnnotationRaw}`,
}: ${propMeta.typeAnnotationRaw}`,
).join(joinStr)
}\n}`
},
Expand Down
20 changes: 10 additions & 10 deletions packages/compiler/src/babel-helpers/ast.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ParseResult } from '@babel/parser'
import type {
CallExpression,
File,
Expand All @@ -6,10 +7,18 @@ import type {
MemberExpression,
Node,
ReturnStatement,
TSPropertySignature,
TaggedTemplateExpression,
TSPropertySignature,
VariableDeclarator,
} from '@babel/types'
import type {
BabelFunctionNodeTypes,
BabelFunctionParams,
Nil,
VINE_MACRO_NAMES,
VineBabelRoot,
VineFnPickedInfo,
} from '../types'
import {
isArrowFunctionExpression,
isCallExpression,
Expand All @@ -28,15 +37,6 @@ import {
isVariableDeclarator,
traverse,
} from '@babel/types'
import type { ParseResult } from '@babel/parser'
import type {
BabelFunctionNodeTypes,
BabelFunctionParams,
Nil,
VINE_MACRO_NAMES,
VineBabelRoot,
VineFnPickedInfo,
} from '../types'
import {
EXPECTED_ERROR,
TS_NODE_TYPES,
Expand Down
26 changes: 13 additions & 13 deletions packages/compiler/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import MagicString from 'magic-string'
import type { Node } from '@babel/types'
import type { VineCompileCtx, VineCompilerCtx, VineCompilerHooks, VineCompilerOptions, VineFileCtx } from './types'
import { findVineCompFnDecls } from './babel-helpers/ast'
import { validateVine } from './validate'
import MagicString from 'magic-string'
import { analyzeVine } from './analyze'
import { transformFile } from './transform'
import { findVineCompFnDecls } from './babel-helpers/ast'
import { babelParse } from './babel-helpers/parse'

export {
compileVineStyle,
} from './style/compile'
import { transformFile } from './transform'
import { validateVine } from './validate'

export {
findVineCompFnDecls,
Expand All @@ -19,15 +15,19 @@ export {
VineBindingTypes,
} from './constants'

export {
compileVineStyle,
} from './style/compile'

export type {
VineFileCtx,
HMRCompFnsName,
VineCompFnCtx as VineFnCompCtx,
VineCompilerOptions,
VineProcessorLang,
VineCompilerCtx,
VineCompilerHooks,
VineCompilerOptions,
VineDiagnostic,
VineCompilerCtx,
HMRCompFnsName,
VineFileCtx,
VineProcessorLang,
} from './types'

export function createCompilerCtx(
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler/src/style/compile.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { RawSourceMap } from 'source-map-js'
import type { Message, ProcessOptions } from 'postcss'
import postcss from 'postcss'
import type { RawSourceMap } from 'source-map-js'
import type { VineCompilerCtx, VineProcessorLang } from '../types'
import postcss from 'postcss'
import { cssVarsPlugin } from './css-vars-plugin'
import { processors } from './preprocessor'
import { scopedPlugin } from './scoped-plugin'
import { trimPlugin } from './trim-plugin'
import { cssVarsPlugin } from './css-vars-plugin'

export async function compileVineStyle(
compilerCtx: VineCompilerCtx,
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/style/css-vars-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PluginCreator } from 'postcss'
import MagicString from 'magic-string'
import type { VineFileCtx } from '../types'
import MagicString from 'magic-string'
import { parseCssVars } from './analyze-css-vars'

interface CSSVarsPluginOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/style/order.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ElementNode } from '@vue/compiler-dom'
import type { VineFileCtx } from '../types'
import { traverseTemplate } from '../template/traverse'
import { isComponentNode, isTemplateElementNode } from '../template/type-predicate'
import type { VineFileCtx } from '../types'
import { createStyleImportStmt } from './create-import-statement'

type ComponentRelationsMap = Record<string, Set<string>>
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/style/preprocessor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import merge from 'merge-source-map'
import type { VineProcessorLang } from '../types'
import type { StylePreprocessor } from './types'
import merge from 'merge-source-map'

// scss/.sass processor
const scss: StylePreprocessor = (source, map, options, load = require) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/compiler/src/style/scoped-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AtRule, PluginCreator, Rule } from 'postcss'
import selectorParser from 'postcss-selector-parser'
import type { VineCompilerCtx, VineFileCtx } from '../types'
import type { DiagnosticParams } from '../diagnostics'
import type { VineCompilerCtx, VineFileCtx } from '../types'
import selectorParser from 'postcss-selector-parser'
import { vineWarn } from '../diagnostics'

const animationNameRE = /^(?:-\w+-)?animation-name$/
Expand Down Expand Up @@ -32,8 +32,8 @@ const scopedPlugin: PluginCreator<ScopedPluginOptions> = (
if (
processedRules.has(rule)
|| (rule.parent
&& rule.parent.type === 'atrule'
&& /-?keyframes$/.test((rule.parent as AtRule).name))
&& rule.parent.type === 'atrule'
&& /-?keyframes$/.test((rule.parent as AtRule).name))
) {
return
}
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler/src/style/transform-css-var.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import MagicString from 'magic-string'
import { traverse } from '@babel/types'
import type { Identifier, Node } from '@babel/types'
import type { VineCompFnCtx, VineTemplateBindings } from '../types'
import { CSS_VARS_HELPER, VineBindingTypes } from '../constants'
import { traverse } from '@babel/types'
import MagicString from 'magic-string'
import { babelParse } from '../babel-helpers/parse'
import { CSS_VARS_HELPER, VineBindingTypes } from '../constants'

function findIdentifierFromExp(scriptContent: string): Identifier[] {
const identifiers: Identifier[] = []
Expand Down
12 changes: 6 additions & 6 deletions packages/compiler/src/template/compose.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { parse as VueCompilerDomParse, compile } from '@vue/compiler-dom'
import { compile as ssrCompile } from '@vue/compiler-ssr'
import type { BindingTypes, CompilerOptions, SourceLocation as VueSourceLocation } from '@vue/compiler-dom'
import type { SourceLocation as BabelSourceLocation, ExportNamedDeclaration, ImportDeclaration, Node } from '@babel/types'
import type { BindingTypes, CompilerOptions, SourceLocation as VueSourceLocation } from '@vue/compiler-dom'
import type { VineCompFnCtx, VineCompilerHooks, VineFileCtx } from '../types'
import { isExportNamedDeclaration, isFunctionDeclaration, isIdentifier, isImportDeclaration, isImportDefaultSpecifier, isImportSpecifier } from '@babel/types'
import { compile, parse as VueCompilerDomParse } from '@vue/compiler-dom'
import { compile as ssrCompile } from '@vue/compiler-ssr'
import lineColumn from 'line-column'
import type { VineCompFnCtx, VineCompilerHooks, VineFileCtx } from '../types'
import { babelParse } from '../babel-helpers/parse'
import { appendToMapArray } from '../utils'
import { vineErr, vineWarn } from '../diagnostics'
import { VineBindingTypes } from '../constants'
import { vineErr, vineWarn } from '../diagnostics'
import { appendToMapArray } from '../utils'

export function compileVineTemplate(
source: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/src/template/importUsageCheck.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { parseExpression } from '@babel/parser'
import type { RootNode, SimpleExpressionNode } from '@vue/compiler-dom'
import type { VineCompFnCtx } from '../types'
import { parseExpression } from '@babel/parser'
import {
parserOptions,
transform,
walkIdentifiers,
} from '@vue/compiler-dom'
import { camelize, capitalize, isBuiltInDirective } from '../utils'
import type { VineCompFnCtx } from '../types'

const templateUsageCheckCache = new Map<string, string>()

Expand Down
35 changes: 18 additions & 17 deletions packages/compiler/src/transform.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { AwaitExpression, Node } from '@babel/types'
import type { MergedImportsMap, NamedImportSpecifierMeta } from './template/compose'
import type { VineCompFnCtx, VineCompilerHooks, VineFileCtx } from './types'
import {
isAssignmentExpression,
isAwaitExpression,
Expand All @@ -7,7 +10,7 @@ import {
isVariableDeclaration,
traverse,
} from '@babel/types'
import type { AwaitExpression, Node } from '@babel/types'
import { isStatementContainsVineMacroCall } from './babel-helpers/ast'
import {
CSS_VARS_HELPER,
DEFINE_COMPONENT_HELPER,
Expand All @@ -19,12 +22,9 @@ import {
USE_SLOT_HELPER,
} from './constants'
import { sortStyleImport } from './style/order'
import type { MergedImportsMap, NamedImportSpecifierMeta } from './template/compose'
import { compileCSSVars } from './style/transform-css-var'
import { createInlineTemplateComposer, createSeparatedTemplateComposer } from './template/compose'
import type { VineCompFnCtx, VineCompilerHooks, VineFileCtx } from './types'
import { filterJoin, showIf } from './utils'
import { isStatementContainsVineMacroCall } from './babel-helpers/ast'
import { compileCSSVars } from './style/transform-css-var'

function wrapWithAsyncContext(
isNeedResult: boolean,
Expand Down Expand Up @@ -152,9 +152,9 @@ function propsOptionsCodeGeneration(
`${modelName}: ${
modelOptions
? vineFileCtx.originCode.slice(
modelOptions.start!,
modelOptions.end!,
)
modelOptions.start!,
modelOptions.end!,
)
: '{}'
},`,
)
Expand Down Expand Up @@ -402,7 +402,8 @@ export function transformFile(
propMeta.default!.start!,
propMeta.default!.end!,
)
}`).join(',\n')
}`)
.join(',\n')
}\n})\n`
}
ms.prependLeft(
Expand Down Expand Up @@ -503,17 +504,17 @@ export function transformFile(
: `${
templateCompileResults.get(vineCompFnCtx) ?? ''
}\n__vine.${ssr ? 'ssrRender' : 'render'} = ${ssr ? '__sfc_ssr_render' : '__sfc_render'}`
}\n${
showIf(
}\n${
showIf(
Boolean(vineFileCtx.styleDefine[vineCompFnCtx.scopeId]),
`__vine.__scopeId = 'data-v-${vineCompFnCtx.scopeId}';`,
)}\n${
isDev ? `__vine.__hmrId = '${vineCompFnCtx.scopeId}';` : ''
}\n${showIf(
// handle Web Component styles
Boolean(vineCompFnCtx.isCustomElement),
`__vine.styles = [__${vineCompFnCtx.fnName.toLowerCase()}_styles];\n`,
)}\nreturn __vine\n})();`)
isDev ? `__vine.__hmrId = '${vineCompFnCtx.scopeId}';` : ''
}\n${showIf(
// handle Web Component styles
Boolean(vineCompFnCtx.isCustomElement),
`__vine.styles = [__${vineCompFnCtx.fnName.toLowerCase()}_styles];\n`,
)}\nreturn __vine\n})();`)

// Record component function to HMR
if (isDev) {
Expand Down
Loading

0 comments on commit 3559bad

Please sign in to comment.