Skip to content

refactor: replace const enum with enum #9263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/compiler-core/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import { ImportItem, TransformContext } from './transform'
// compilers.
export type Namespace = number

export const enum Namespaces {
export enum Namespaces {
HTML
}

export const enum NodeTypes {
export enum NodeTypes {
ROOT,
ELEMENT,
TEXT,
Expand Down Expand Up @@ -59,7 +59,7 @@ export const enum NodeTypes {
JS_RETURN_STATEMENT
}

export const enum ElementTypes {
export enum ElementTypes {
ELEMENT,
COMPONENT,
SLOT,
Expand Down Expand Up @@ -202,7 +202,7 @@ export interface DirectiveNode extends Node {
* Higher levels implies lower levels. e.g. a node that can be stringified
* can always be hoisted and skipped for patch.
*/
export const enum ConstantTypes {
export enum ConstantTypes {
NOT_CONSTANT = 0,
CAN_SKIP_PATCH,
CAN_HOIST,
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/compat/compatConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface CompilerCompatOptions {
compatConfig?: CompilerCompatConfig
}

export const enum CompilerDeprecationTypes {
export enum CompilerDeprecationTypes {
COMPILER_IS_ON_ELEMENT = 'COMPILER_IS_ON_ELEMENT',
COMPILER_V_BIND_SYNC = 'COMPILER_V_BIND_SYNC',
COMPILER_V_BIND_PROP = 'COMPILER_V_BIND_PROP',
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function createCompilerError<T extends number>(
return error
}

export const enum ErrorCodes {
export enum ErrorCodes {
// parse errors
ABRUPT_CLOSING_OF_EMPTY_COMMENT,
CDATA_IN_HTML_CONTENT,
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export type HoistTransform = (
parent: ParentNode
) => void

export const enum BindingTypes {
export enum BindingTypes {
/**
* returned from data()
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const defaultParserOptions: MergedParserOptions = {
comments: __DEV__
}

export const enum TextModes {
export enum TextModes {
// | Elements | Entities | End sign | Inside of
DATA, // | ✔ | ✔ | End tags of ancestors |
RCDATA, // | ✘ | ✔ | End tag of the parent | <textarea>
Expand Down Expand Up @@ -502,7 +502,7 @@ function parseElement(
return element
}

const enum TagType {
enum TagType {
Start,
End
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const nonIdentifierRE = /^\d|[^\$\w]/
export const isSimpleIdentifier = (name: string): boolean =>
!nonIdentifierRE.test(name)

const enum MemberExpLexState {
enum MemberExpLexState {
inMemberExp,
inBrackets,
inParens,
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-dom/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function createDOMCompilerError(
) as DOMCompilerError
}

export const enum DOMErrorCodes {
export enum DOMErrorCodes {
X_V_HTML_NO_EXPRESSION = 53 /* ErrorCodes.__EXTEND_POINT__ */,
X_V_HTML_WITH_CHILDREN,
X_V_TEXT_NO_EXPRESSION,
Expand All @@ -36,7 +36,7 @@ export const enum DOMErrorCodes {
}

if (__TEST__) {
// esbuild cannot infer const enum increments if first value is from another
// esbuild cannot infer enum increments if first value is from another
// file, so we have to manually keep them in sync. this check ensures it
// errors out if there are collisions.
if (DOMErrorCodes.X_V_HTML_NO_EXPRESSION < ErrorCodes.__EXTEND_POINT__) {
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-dom/src/parserOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const isRawTextContainer = /*#__PURE__*/ makeMap(
true
)

export const enum DOMNamespaces {
export enum DOMNamespaces {
HTML = 0 /* Namespaces.HTML */,
SVG,
MATH_ML
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-dom/src/transforms/stringifyStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from '@vue/shared'
import { DOMNamespaces } from '../parserOptions'

export const enum StringifyThresholds {
export enum StringifyThresholds {
ELEMENT_WITH_BINDING_COUNT = 5,
NODE_COUNT = 20
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/style/cssVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function parseCssVars(sfc: SFCDescriptor): string[] {
return vars
}

const enum LexerState {
enum LexerState {
inParens,
inSingleQuoteString,
inDoubleQuoteString
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-ssr/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export function createSSRCompilerError(
return createCompilerError(code, loc, SSRErrorMessages) as SSRCompilerError
}

export const enum SSRErrorCodes {
export enum SSRErrorCodes {
X_SSR_UNSAFE_ATTR_NAME = 65 /* DOMErrorCodes.__EXTEND_POINT__ */,
X_SSR_NO_TELEPORT_TARGET,
X_SSR_INVALID_AST_NODE
}

if (__TEST__) {
// esbuild cannot infer const enum increments if first value is from another
// esbuild cannot infer enum increments if first value is from another
// file, so we have to manually keep them in sync. this check ensures it
// errors out if there are collisions.
if (SSRErrorCodes.X_SSR_UNSAFE_ATTR_NAME < DOMErrorCodes.__EXTEND_POINT__) {
Expand Down
7 changes: 2 additions & 5 deletions packages/reactivity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export {
shallowReadonly,
markRaw,
toRaw,
ReactiveFlags /* @remove */,
ReactiveFlags,
type Raw,
type DeepReadonly,
type ShallowReactive,
Expand Down Expand Up @@ -69,7 +69,4 @@ export {
getCurrentScope,
onScopeDispose
} from './effectScope'
export {
TrackOpTypes /* @remove */,
TriggerOpTypes /* @remove */
} from './operations'
export { TrackOpTypes, TriggerOpTypes } from './operations'
4 changes: 2 additions & 2 deletions packages/reactivity/src/operations.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// using literal strings instead of numbers so that it's easier to inspect
// debugger events

export const enum TrackOpTypes {
export enum TrackOpTypes {
GET = 'get',
HAS = 'has',
ITERATE = 'iterate'
}

export const enum TriggerOpTypes {
export enum TriggerOpTypes {
SET = 'set',
ADD = 'add',
DELETE = 'delete',
Expand Down
4 changes: 2 additions & 2 deletions packages/reactivity/src/reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from './collectionHandlers'
import type { UnwrapRefSimple, Ref, RawSymbol } from './ref'

export const enum ReactiveFlags {
export enum ReactiveFlags {
SKIP = '__v_skip',
IS_REACTIVE = '__v_isReactive',
IS_READONLY = '__v_isReadonly',
Expand All @@ -34,7 +34,7 @@ export const shallowReactiveMap = new WeakMap<Target, any>()
export const readonlyMap = new WeakMap<Target, any>()
export const shallowReadonlyMap = new WeakMap<Target, any>()

const enum TargetType {
enum TargetType {
INVALID = 0,
COMMON = 1,
COLLECTION = 2
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/compat/compatConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../component'
import { warn } from '../warning'

export const enum DeprecationTypes {
export enum DeprecationTypes {
GLOBAL_MOUNT = 'GLOBAL_MOUNT',
GLOBAL_MOUNT_CONTAINER = 'GLOBAL_MOUNT_CONTAINER',
GLOBAL_EXTEND = 'GLOBAL_EXTEND',
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ export type OptionTypesType<
Defaults: Defaults
}

const enum OptionTypes {
enum OptionTypes {
PROPS = 'Props',
DATA = 'Data',
COMPUTED = 'Computed',
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export type ExtractPublicPropTypes<O> = {
[K in keyof Pick<O, PublicOptionalKeys<O>>]?: InferPropType<O[K]>
}

const enum BooleanFlags {
enum BooleanFlags {
shouldCast,
shouldCastTrue
}
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentPublicInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ if (__COMPAT__) {
installCompatInstanceProperties(publicPropertiesMap)
}

const enum AccessTypes {
enum AccessTypes {
OTHER,
SETUP,
DATA,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/components/Teleport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export const TeleportImpl = {
hydrate: hydrateTeleport
}

export const enum TeleportMoveTypes {
export enum TeleportMoveTypes {
TARGET_CHANGE,
TOGGLE, // enable / disable
REORDER // moved in the main view
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface AppRecord {
types: Record<string, string | Symbol>
}

const enum DevtoolsHooks {
enum DevtoolsHooks {
APP_INIT = 'app:init',
APP_UNMOUNT = 'app:unmount',
COMPONENT_UPDATED = 'component:updated',
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/enums.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const enum LifecycleHooks {
export enum LifecycleHooks {
BEFORE_CREATE = 'bc',
CREATED = 'c',
BEFORE_MOUNT = 'bm',
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/errorHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LifecycleHooks } from './enums'

// contexts where user provided function may be executed, in addition to
// lifecycle hooks.
export const enum ErrorCodes {
export enum ErrorCodes {
SETUP_FUNCTION,
RENDER_FUNCTION,
WATCH_GETTER,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/hydration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type RootHydrateFunction = (
container: (Element | ShadowRoot) & { _vnode?: VNode }
) => void

const enum DOMNodeTypes {
enum DOMNodeTypes {
ELEMENT = 1,
TEXT = 3,
COMMENT = 8
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export type SetupRenderEffectFn = (
optimized: boolean
) => void

export const enum MoveType {
export enum MoveType {
ENTER,
LEAVE,
REORDER
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-test/src/nodeOps.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { markRaw } from '@vue/reactivity'

export const enum TestNodeTypes {
export enum TestNodeTypes {
TEXT = 'text',
ELEMENT = 'element',
COMMENT = 'comment'
}

export const enum NodeOpTypes {
export enum NodeOpTypes {
CREATE = 'create',
INSERT = 'insert',
REMOVE = 'remove',
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/patchFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Check the `patchElement` function in '../../runtime-core/src/renderer.ts' to see how the
* flags are handled during diff.
*/
export const enum PatchFlags {
export enum PatchFlags {
/**
* Indicates an element with dynamic textContent (children fast path)
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/shapeFlags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const enum ShapeFlags {
export enum ShapeFlags {
ELEMENT = 1,
FUNCTIONAL_COMPONENT = 1 << 1,
STATEFUL_COMPONENT = 1 << 2,
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/slotFlags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const enum SlotFlags {
export enum SlotFlags {
/**
* Stable slots that only reference slot props or context state. The slot
* can fully capture its own dependencies so when passed down the parent won't
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/macros.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {

export declare const RefType: unique symbol

export declare const enum RefTypes {
export declare enum RefTypes {
Ref = 1,
ComputedRef = 2,
WritableComputedRef = 3
Expand Down
5 changes: 2 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import terser from '@rollup/plugin-terser'
import esbuild from 'rollup-plugin-esbuild'
import alias from '@rollup/plugin-alias'
import { entries } from './scripts/aliases.js'
import { constEnum } from './scripts/const-enum.js'
import { enums } from './scripts/enum.js'

if (!process.env.TARGET) {
throw new Error('TARGET package must be specified via --environment flag.')
Expand All @@ -32,7 +32,7 @@ const pkg = require(resolve(`package.json`))
const packageOptions = pkg.buildOptions || {}
const name = packageOptions.filename || path.basename(packageDir)

const [enumPlugin, enumDefines] = constEnum()
const enumDefines = enums()

const outputConfigs = {
'esm-bundler': {
Expand Down Expand Up @@ -285,7 +285,6 @@ function createConfig(format, output, plugins = []) {
alias({
entries
}),
enumPlugin,
...resolveReplace(),
esbuild({
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ nr build core --formats cjs
*/

import fs from 'node:fs/promises'
import { existsSync, readFileSync } from 'node:fs'
import { existsSync } from 'node:fs'
import path from 'node:path'
import minimist from 'minimist'
import { gzipSync, brotliCompressSync } from 'node:zlib'
Expand All @@ -26,7 +26,7 @@ import { execa, execaSync } from 'execa'
import { cpus } from 'node:os'
import { createRequire } from 'node:module'
import { targets as allTargets, fuzzyMatchTarget } from './utils.js'
import { scanEnums } from './const-enum.js'
import { scanEnums } from './enum.js'
import prettyBytes from 'pretty-bytes'

const require = createRequire(import.meta.url)
Expand Down
Loading