Skip to content

Commit f3092e5

Browse files
committed
feat: use enum to replace const enum
1 parent b8fc18c commit f3092e5

34 files changed

+143
-105
lines changed

.eslintrc.cjs

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

4+
const banConstEnum = {
5+
selector: 'TSEnumDeclaration[const=true]',
6+
message: 'Please use enums, instead',
7+
}
8+
9+
/**
10+
* @type {import('eslint-define-config').ESLintConfig}
11+
*/
412
module.exports = {
513
parser: '@typescript-eslint/parser',
614
parserOptions: {
@@ -20,6 +28,7 @@ module.exports = {
2028

2129
'no-restricted-syntax': [
2230
'error',
31+
banConstEnum,
2332
// since we target ES2015 for baseline support, we need to forbid object
2433
// rest spread usage in destructure as it compiles into a verbose helper.
2534
'ObjectPattern > RestElement',
@@ -61,23 +70,32 @@ module.exports = {
6170
],
6271
rules: {
6372
'no-restricted-globals': ['error', ...DOMGlobals],
64-
'no-restricted-syntax': 'off'
73+
'no-restricted-syntax': [
74+
'error',
75+
banConstEnum,
76+
]
6577
}
6678
},
6779
// Private package, browser only + no syntax restrictions
6880
{
6981
files: ['packages/template-explorer/**', 'packages/sfc-playground/**'],
7082
rules: {
7183
'no-restricted-globals': ['error', ...NodeGlobals],
72-
'no-restricted-syntax': 'off'
84+
'no-restricted-syntax': [
85+
'error',
86+
banConstEnum,
87+
]
7388
}
7489
},
7590
// Node scripts
7691
{
7792
files: ['scripts/**', '*.{js,ts}', 'packages/**/index.js'],
7893
rules: {
7994
'no-restricted-globals': 'off',
80-
'no-restricted-syntax': 'off'
95+
'no-restricted-syntax': [
96+
'error',
97+
banConstEnum,
98+
]
8199
}
82100
}
83101
]

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"esbuild": "^0.19.3",
7777
"esbuild-plugin-polyfill-node": "^0.3.0",
7878
"eslint": "^8.49.0",
79+
"eslint-define-config": "^1.23.0",
7980
"eslint-plugin-jest": "^27.4.0",
8081
"estree-walker": "^2.0.2",
8182
"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)