From b2c874e3b9b3bdcab43f99ea80c264c16b448473 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 5 Apr 2023 16:35:10 +0800 Subject: [PATCH] refactor(compiler-sfc): move related files into separate directories --- .../__tests__/templateTransformAssetUrl.spec.ts | 2 +- .../__tests__/templateTransformSrcset.spec.ts | 4 ++-- packages/compiler-sfc/__tests__/templateUtils.spec.ts | 2 +- packages/compiler-sfc/src/compileScript.ts | 4 ++-- packages/compiler-sfc/src/compileStyle.ts | 8 ++++---- packages/compiler-sfc/src/compileTemplate.ts | 6 +++--- packages/compiler-sfc/src/index.ts | 2 +- packages/compiler-sfc/src/parse.ts | 2 +- .../propsDestructure.ts} | 2 +- packages/compiler-sfc/src/{ => style}/cssVars.ts | 2 +- .../src/{stylePluginScoped.ts => style/pluginScoped.ts} | 2 +- .../src/{stylePluginTrim.ts => style/pluginTrim.ts} | 0 .../src/{stylePreprocessors.ts => style/preprocessors.ts} | 2 +- packages/compiler-sfc/src/{ => template}/templateUtils.ts | 0 .../transformAssetUrl.ts} | 0 .../transformSrcset.ts} | 5 +---- 16 files changed, 20 insertions(+), 23 deletions(-) rename packages/compiler-sfc/src/{compileScriptPropsDestructure.ts => script/propsDestructure.ts} (99%) rename packages/compiler-sfc/src/{ => style}/cssVars.ts (99%) rename packages/compiler-sfc/src/{stylePluginScoped.ts => style/pluginScoped.ts} (99%) rename packages/compiler-sfc/src/{stylePluginTrim.ts => style/pluginTrim.ts} (100%) rename packages/compiler-sfc/src/{stylePreprocessors.ts => style/preprocessors.ts} (98%) rename packages/compiler-sfc/src/{ => template}/templateUtils.ts (100%) rename packages/compiler-sfc/src/{templateTransformAssetUrl.ts => template/transformAssetUrl.ts} (100%) rename packages/compiler-sfc/src/{templateTransformSrcset.ts => template/transformSrcset.ts} (98%) diff --git a/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts b/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts index 0b0f138b8a8..f267e73ede0 100644 --- a/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts +++ b/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts @@ -9,7 +9,7 @@ import { createAssetUrlTransformWithOptions, AssetURLOptions, normalizeOptions -} from '../src/templateTransformAssetUrl' +} from '../src/template/transformAssetUrl' import { transformElement } from '../../compiler-core/src/transforms/transformElement' import { transformBind } from '../../compiler-core/src/transforms/vBind' import { stringifyStatic } from '../../compiler-dom/src/transforms/stringifyStatic' diff --git a/packages/compiler-sfc/__tests__/templateTransformSrcset.spec.ts b/packages/compiler-sfc/__tests__/templateTransformSrcset.spec.ts index 8c21dd41656..174e3ca9f79 100644 --- a/packages/compiler-sfc/__tests__/templateTransformSrcset.spec.ts +++ b/packages/compiler-sfc/__tests__/templateTransformSrcset.spec.ts @@ -7,13 +7,13 @@ import { import { transformSrcset, createSrcsetTransformWithOptions -} from '../src/templateTransformSrcset' +} from '../src/template/transformSrcset' import { transformElement } from '../../compiler-core/src/transforms/transformElement' import { transformBind } from '../../compiler-core/src/transforms/vBind' import { AssetURLOptions, normalizeOptions -} from '../src/templateTransformAssetUrl' +} from '../src/template/transformAssetUrl' import { stringifyStatic } from '../../compiler-dom/src/transforms/stringifyStatic' function compileWithSrcset( diff --git a/packages/compiler-sfc/__tests__/templateUtils.spec.ts b/packages/compiler-sfc/__tests__/templateUtils.spec.ts index a509657332a..7e20603848c 100644 --- a/packages/compiler-sfc/__tests__/templateUtils.spec.ts +++ b/packages/compiler-sfc/__tests__/templateUtils.spec.ts @@ -2,7 +2,7 @@ import { isRelativeUrl, isExternalUrl, isDataUrl -} from '../../compiler-sfc/src/templateUtils' +} from '../src/template/templateUtils' describe('compiler sfc:templateUtils isRelativeUrl', () => { test('should return true when The first character of the string path is .', () => { diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 1f1385b25fd..4902bea7a2c 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -53,13 +53,13 @@ import { CSS_VARS_HELPER, genCssVarsCode, genNormalScriptCssVarsCode -} from './cssVars' +} from './style/cssVars' import { compileTemplate, SFCTemplateCompileOptions } from './compileTemplate' import { warnOnce } from './warn' import { rewriteDefaultAST } from './rewriteDefault' import { createCache } from './cache' import { shouldTransform, transformAST } from '@vue/reactivity-transform' -import { transformDestructuredProps } from './compileScriptPropsDestructure' +import { transformDestructuredProps } from './script/propsDestructure' // Special compiler macros const DEFINE_PROPS = 'defineProps' diff --git a/packages/compiler-sfc/src/compileStyle.ts b/packages/compiler-sfc/src/compileStyle.ts index 8e02eaf6ca8..1885569635d 100644 --- a/packages/compiler-sfc/src/compileStyle.ts +++ b/packages/compiler-sfc/src/compileStyle.ts @@ -5,16 +5,16 @@ import postcss, { Message, LazyResult } from 'postcss' -import trimPlugin from './stylePluginTrim' -import scopedPlugin from './stylePluginScoped' +import trimPlugin from './style/pluginTrim' +import scopedPlugin from './style/pluginScoped' import { processors, StylePreprocessor, StylePreprocessorResults, PreprocessLang -} from './stylePreprocessors' +} from './style/preprocessors' import { RawSourceMap } from 'source-map' -import { cssVarsPlugin } from './cssVars' +import { cssVarsPlugin } from './style/cssVars' import postcssModules from 'postcss-modules' export interface SFCStyleCompileOptions { diff --git a/packages/compiler-sfc/src/compileTemplate.ts b/packages/compiler-sfc/src/compileTemplate.ts index 2654da105a7..9ada0e7557f 100644 --- a/packages/compiler-sfc/src/compileTemplate.ts +++ b/packages/compiler-sfc/src/compileTemplate.ts @@ -13,17 +13,17 @@ import { createAssetUrlTransformWithOptions, AssetURLTagConfig, normalizeOptions -} from './templateTransformAssetUrl' +} from './template/transformAssetUrl' import { transformSrcset, createSrcsetTransformWithOptions -} from './templateTransformSrcset' +} from './template/transformSrcset' import { generateCodeFrame, isObject } from '@vue/shared' import * as CompilerDOM from '@vue/compiler-dom' import * as CompilerSSR from '@vue/compiler-ssr' import consolidate from '@vue/consolidate' import { warnOnce } from './warn' -import { genCssVarsFromList } from './cssVars' +import { genCssVarsFromList } from './style/cssVars' export interface TemplateCompiler { compile(template: string, options: CompilerOptions): CodegenResult diff --git a/packages/compiler-sfc/src/index.ts b/packages/compiler-sfc/src/index.ts index c73276d9c91..6ba097b2466 100644 --- a/packages/compiler-sfc/src/index.ts +++ b/packages/compiler-sfc/src/index.ts @@ -52,7 +52,7 @@ export type { SFCScriptCompileOptions } from './compileScript' export type { AssetURLOptions, AssetURLTagConfig -} from './templateTransformAssetUrl' +} from './template/transformAssetUrl' export type { CompilerOptions, CompilerError, diff --git a/packages/compiler-sfc/src/parse.ts b/packages/compiler-sfc/src/parse.ts index 79065fc667e..d2b98756c49 100644 --- a/packages/compiler-sfc/src/parse.ts +++ b/packages/compiler-sfc/src/parse.ts @@ -9,7 +9,7 @@ import { import * as CompilerDOM from '@vue/compiler-dom' import { RawSourceMap, SourceMapGenerator } from 'source-map' import { TemplateCompiler } from './compileTemplate' -import { parseCssVars } from './cssVars' +import { parseCssVars } from './style/cssVars' import { createCache } from './cache' import { hmrShouldReload, ImportBinding } from './compileScript' diff --git a/packages/compiler-sfc/src/compileScriptPropsDestructure.ts b/packages/compiler-sfc/src/script/propsDestructure.ts similarity index 99% rename from packages/compiler-sfc/src/compileScriptPropsDestructure.ts rename to packages/compiler-sfc/src/script/propsDestructure.ts index d0addf6fcbc..cd1fe36a2f9 100644 --- a/packages/compiler-sfc/src/compileScriptPropsDestructure.ts +++ b/packages/compiler-sfc/src/script/propsDestructure.ts @@ -18,7 +18,7 @@ import { unwrapTSNode } from '@vue/compiler-core' import { genPropsAccessExp } from '@vue/shared' -import { PropsDestructureBindings } from './compileScript' +import { PropsDestructureBindings } from '../compileScript' /** * true -> prop binding diff --git a/packages/compiler-sfc/src/cssVars.ts b/packages/compiler-sfc/src/style/cssVars.ts similarity index 99% rename from packages/compiler-sfc/src/cssVars.ts rename to packages/compiler-sfc/src/style/cssVars.ts index 411e48cb76a..f232d09695d 100644 --- a/packages/compiler-sfc/src/cssVars.ts +++ b/packages/compiler-sfc/src/style/cssVars.ts @@ -7,7 +7,7 @@ import { SimpleExpressionNode, BindingMetadata } from '@vue/compiler-dom' -import { SFCDescriptor } from './parse' +import { SFCDescriptor } from '../parse' import { PluginCreator } from 'postcss' import hash from 'hash-sum' diff --git a/packages/compiler-sfc/src/stylePluginScoped.ts b/packages/compiler-sfc/src/style/pluginScoped.ts similarity index 99% rename from packages/compiler-sfc/src/stylePluginScoped.ts rename to packages/compiler-sfc/src/style/pluginScoped.ts index c4576009495..1dcc248ad71 100644 --- a/packages/compiler-sfc/src/stylePluginScoped.ts +++ b/packages/compiler-sfc/src/style/pluginScoped.ts @@ -1,6 +1,6 @@ import { PluginCreator, Rule, AtRule } from 'postcss' import selectorParser from 'postcss-selector-parser' -import { warn } from './warn' +import { warn } from '../warn' const animationNameRE = /^(-\w+-)?animation-name$/ const animationRE = /^(-\w+-)?animation$/ diff --git a/packages/compiler-sfc/src/stylePluginTrim.ts b/packages/compiler-sfc/src/style/pluginTrim.ts similarity index 100% rename from packages/compiler-sfc/src/stylePluginTrim.ts rename to packages/compiler-sfc/src/style/pluginTrim.ts diff --git a/packages/compiler-sfc/src/stylePreprocessors.ts b/packages/compiler-sfc/src/style/preprocessors.ts similarity index 98% rename from packages/compiler-sfc/src/stylePreprocessors.ts rename to packages/compiler-sfc/src/style/preprocessors.ts index 218ebfdb430..06122f2e6b3 100644 --- a/packages/compiler-sfc/src/stylePreprocessors.ts +++ b/packages/compiler-sfc/src/style/preprocessors.ts @@ -1,6 +1,6 @@ import merge from 'merge-source-map' import { RawSourceMap } from 'source-map' -import { SFCStyleCompileOptions } from './compileStyle' +import { SFCStyleCompileOptions } from '../compileStyle' import { isFunction } from '@vue/shared' export type StylePreprocessor = ( diff --git a/packages/compiler-sfc/src/templateUtils.ts b/packages/compiler-sfc/src/template/templateUtils.ts similarity index 100% rename from packages/compiler-sfc/src/templateUtils.ts rename to packages/compiler-sfc/src/template/templateUtils.ts diff --git a/packages/compiler-sfc/src/templateTransformAssetUrl.ts b/packages/compiler-sfc/src/template/transformAssetUrl.ts similarity index 100% rename from packages/compiler-sfc/src/templateTransformAssetUrl.ts rename to packages/compiler-sfc/src/template/transformAssetUrl.ts diff --git a/packages/compiler-sfc/src/templateTransformSrcset.ts b/packages/compiler-sfc/src/template/transformSrcset.ts similarity index 98% rename from packages/compiler-sfc/src/templateTransformSrcset.ts rename to packages/compiler-sfc/src/template/transformSrcset.ts index 9780f93b5c5..18b9d0b0b3b 100644 --- a/packages/compiler-sfc/src/templateTransformSrcset.ts +++ b/packages/compiler-sfc/src/template/transformSrcset.ts @@ -14,10 +14,7 @@ import { isExternalUrl, isDataUrl } from './templateUtils' -import { - AssetURLOptions, - defaultAssetUrlOptions -} from './templateTransformAssetUrl' +import { AssetURLOptions, defaultAssetUrlOptions } from './transformAssetUrl' const srcsetTags = ['img', 'source']