Skip to content

Commit 07c6b95

Browse files
committed
feat: use enum to replace const enum
1 parent 2c0414f commit 07c6b95

37 files changed

+356
-305
lines changed

.eslintrc.cjs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
const DOMGlobals = ['window', 'document']
44
const NodeGlobals = ['module', 'require']
55

6+
const banConstEnum = {
7+
selector: 'TSEnumDeclaration[const=true]',
8+
message: 'Please use enums, instead',
9+
}
10+
11+
/**
12+
* @type {import('eslint-define-config').ESLintConfig}
13+
*/
614
module.exports = {
715
parser: '@typescript-eslint/parser',
816
parserOptions: {
@@ -16,6 +24,7 @@ module.exports = {
1624

1725
'no-restricted-syntax': [
1826
'error',
27+
banConstEnum,
1928
// since we target ES2015 for baseline support, we need to forbid object
2029
// rest spread usage in destructure as it compiles into a verbose helper.
2130
'ObjectPattern > RestElement',
@@ -57,15 +66,21 @@ module.exports = {
5766
],
5867
rules: {
5968
'no-restricted-globals': ['error', ...DOMGlobals],
60-
'no-restricted-syntax': 'off'
69+
'no-restricted-syntax': [
70+
'error',
71+
banConstEnum,
72+
]
6173
}
6274
},
6375
// Private package, browser only + no syntax restrictions
6476
{
6577
files: ['packages/template-explorer/**', 'packages/sfc-playground/**'],
6678
rules: {
6779
'no-restricted-globals': ['error', ...NodeGlobals],
68-
'no-restricted-syntax': 'off'
80+
'no-restricted-syntax': [
81+
'error',
82+
banConstEnum,
83+
]
6984
}
7085
},
7186
// JavaScript files
@@ -81,7 +96,10 @@ module.exports = {
8196
files: ['scripts/**', '*.{js,ts}', 'packages/**/index.js'],
8297
rules: {
8398
'no-restricted-globals': 'off',
84-
'no-restricted-syntax': 'off'
99+
'no-restricted-syntax': [
100+
'error',
101+
banConstEnum,
102+
]
85103
}
86104
}
87105
]

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"esbuild": "^0.19.5",
7676
"esbuild-plugin-polyfill-node": "^0.3.0",
7777
"eslint": "^8.52.0",
78+
"eslint-define-config": "^1.24.1",
7879
"eslint-plugin-jest": "^27.6.0",
7980
"estree-walker": "^2.0.2",
8081
"execa": "^8.0.1",

packages/compiler-core/src/ast.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import { ImportItem, TransformContext } from './transform'
2121
// compilers.
2222
export type Namespace = number
2323

24-
export const enum Namespaces {
24+
export enum Namespaces {
2525
HTML
2626
}
2727

28-
export const enum NodeTypes {
28+
export enum NodeTypes {
2929
ROOT,
3030
ELEMENT,
3131
TEXT,
@@ -59,7 +59,7 @@ export const enum NodeTypes {
5959
JS_RETURN_STATEMENT
6060
}
6161

62-
export const enum ElementTypes {
62+
export enum ElementTypes {
6363
ELEMENT,
6464
COMPONENT,
6565
SLOT,
@@ -202,7 +202,7 @@ export interface DirectiveNode extends Node {
202202
* Higher levels implies lower levels. e.g. a node that can be stringified
203203
* can always be hoisted and skipped for patch.
204204
*/
205-
export const enum ConstantTypes {
205+
export enum ConstantTypes {
206206
NOT_CONSTANT = 0,
207207
CAN_SKIP_PATCH,
208208
CAN_HOIST,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface CompilerCompatOptions {
1313
compatConfig?: CompilerCompatConfig
1414
}
1515

16-
export const enum CompilerDeprecationTypes {
16+
export enum CompilerDeprecationTypes {
1717
COMPILER_IS_ON_ELEMENT = 'COMPILER_IS_ON_ELEMENT',
1818
COMPILER_V_BIND_SYNC = 'COMPILER_V_BIND_SYNC',
1919
COMPILER_V_BIND_PROP = 'COMPILER_V_BIND_PROP',

packages/compiler-core/src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function createCompilerError<T extends number>(
3737
return error
3838
}
3939

40-
export const enum ErrorCodes {
40+
export enum ErrorCodes {
4141
// parse errors
4242
ABRUPT_CLOSING_OF_EMPTY_COMMENT,
4343
CDATA_IN_HTML_CONTENT,

packages/compiler-core/src/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export type HoistTransform = (
7373
parent: ParentNode
7474
) => void
7575

76-
export const enum BindingTypes {
76+
export enum BindingTypes {
7777
/**
7878
* returned from data()
7979
*/

packages/compiler-core/src/parse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const defaultParserOptions: MergedParserOptions = {
8080
comments: __DEV__
8181
}
8282

83-
export const enum TextModes {
83+
export enum TextModes {
8484
// | Elements | Entities | End sign | Inside of
8585
DATA, // | ✔ | ✔ | End tags of ancestors |
8686
RCDATA, // | ✘ | ✔ | End tag of the parent | <textarea>
@@ -502,7 +502,7 @@ function parseElement(
502502
return element
503503
}
504504

505-
const enum TagType {
505+
enum TagType {
506506
Start,
507507
End
508508
}

packages/compiler-core/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const nonIdentifierRE = /^\d|[^\$\w]/
6464
export const isSimpleIdentifier = (name: string): boolean =>
6565
!nonIdentifierRE.test(name)
6666

67-
const enum MemberExpLexState {
67+
enum MemberExpLexState {
6868
inMemberExp,
6969
inBrackets,
7070
inParens,

packages/compiler-dom/src/errors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function createDOMCompilerError(
2020
) as DOMCompilerError
2121
}
2222

23-
export const enum DOMErrorCodes {
23+
export enum DOMErrorCodes {
2424
X_V_HTML_NO_EXPRESSION = 53 /* ErrorCodes.__EXTEND_POINT__ */,
2525
X_V_HTML_WITH_CHILDREN,
2626
X_V_TEXT_NO_EXPRESSION,
@@ -36,7 +36,7 @@ export const enum DOMErrorCodes {
3636
}
3737

3838
if (__TEST__) {
39-
// esbuild cannot infer const enum increments if first value is from another
39+
// esbuild cannot infer enum increments if first value is from another
4040
// file, so we have to manually keep them in sync. this check ensures it
4141
// errors out if there are collisions.
4242
if (DOMErrorCodes.X_V_HTML_NO_EXPRESSION < ErrorCodes.__EXTEND_POINT__) {

packages/compiler-dom/src/parserOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const isRawTextContainer = /*#__PURE__*/ makeMap(
1515
true
1616
)
1717

18-
export const enum DOMNamespaces {
18+
export enum DOMNamespaces {
1919
HTML = 0 /* Namespaces.HTML */,
2020
SVG,
2121
MATH_ML

0 commit comments

Comments
 (0)