-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
feat: use enum to replace const enum #9261
Conversation
❌ Deploy Preview for vue-sfc-playground failed.
|
❌ Deploy Preview for vue-next-template-explorer failed.
|
601be9e
to
1b49736
Compare
Size ReportBundles
Usages
|
A competition PR #9263 😁 |
@yangmingshan My PR did not consider enum reverse mapping, which is unsafe. Your PR is more safe. |
c045410
to
f3092e5
Compare
24471b9
to
9992964
Compare
@sxzz Can we rerun the size bot? So we can compare the size. |
@yangmingshan It's not about vue's size. It's about the size of application which using the new export enum. |
I think this has a very slight impact on the size of the application. |
Some source code in packages/compiler-core/src/errors.tsexport enum ErrorCodes {
// parse errors
ABRUPT_CLOSING_OF_EMPTY_COMMENT,
CDATA_IN_HTML_CONTENT,
DUPLICATE_ATTRIBUTE,
END_TAG_WITH_ATTRIBUTES,
END_TAG_WITH_TRAILING_SOLIDUS,
EOF_BEFORE_TAG_NAME,
EOF_IN_CDATA,
EOF_IN_COMMENT,
EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT,
EOF_IN_TAG,
INCORRECTLY_CLOSED_COMMENT,
INCORRECTLY_OPENED_COMMENT,
INVALID_FIRST_CHARACTER_OF_TAG_NAME,
MISSING_ATTRIBUTE_VALUE,
MISSING_END_TAG_NAME,
MISSING_WHITESPACE_BETWEEN_ATTRIBUTES,
NESTED_COMMENT,
UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME,
UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE,
UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME,
UNEXPECTED_NULL_CHARACTER,
UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME,
UNEXPECTED_SOLIDUS_IN_TAG,
// Vue-specific parse errors
X_INVALID_END_TAG,
X_MISSING_END_TAG,
X_MISSING_INTERPOLATION_END,
X_MISSING_DIRECTIVE_NAME,
X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END,
// transform errors
X_V_IF_NO_EXPRESSION,
X_V_IF_SAME_KEY,
X_V_ELSE_NO_ADJACENT_IF,
X_V_FOR_NO_EXPRESSION,
X_V_FOR_MALFORMED_EXPRESSION,
X_V_FOR_TEMPLATE_KEY_PLACEMENT,
X_V_BIND_NO_EXPRESSION,
X_V_ON_NO_EXPRESSION,
X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET,
X_V_SLOT_MIXED_SLOT_USAGE,
X_V_SLOT_DUPLICATE_SLOT_NAMES,
X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN,
X_V_SLOT_MISPLACED,
X_V_MODEL_NO_EXPRESSION,
X_V_MODEL_MALFORMED_EXPRESSION,
X_V_MODEL_ON_SCOPE_VARIABLE,
X_V_MODEL_ON_PROPS,
X_INVALID_EXPRESSION,
X_KEEP_ALIVE_INVALID_CHILDREN,
// generic errors
X_PREFIX_ID_NOT_SUPPORTED,
X_MODULE_MODE_NOT_SUPPORTED,
X_CACHE_HANDLER_NOT_SUPPORTED,
X_SCOPE_ID_NOT_SUPPORTED,
// deprecations
DEPRECATION_VNODE_HOOKS,
DEPRECATION_V_IS,
// Special value for higher-order compilers to pick up the last code
// to avoid collision of error codes. This should always be kept as the last
// item.
__EXTEND_POINT__
} Try to code code below to here const ErrorCodesObject = {
"ABRUPT_CLOSING_OF_EMPTY_COMMENT": 0,
"0": "ABRUPT_CLOSING_OF_EMPTY_COMMENT",
"CDATA_IN_HTML_CONTENT": 1,
"1": "CDATA_IN_HTML_CONTENT",
"DUPLICATE_ATTRIBUTE": 2,
"2": "DUPLICATE_ATTRIBUTE",
"END_TAG_WITH_ATTRIBUTES": 3,
"3": "END_TAG_WITH_ATTRIBUTES",
"END_TAG_WITH_TRAILING_SOLIDUS": 4,
"4": "END_TAG_WITH_TRAILING_SOLIDUS",
"EOF_BEFORE_TAG_NAME": 5,
"5": "EOF_BEFORE_TAG_NAME",
"EOF_IN_CDATA": 6,
"6": "EOF_IN_CDATA",
"EOF_IN_COMMENT": 7,
"7": "EOF_IN_COMMENT",
"EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT": 8,
"8": "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT",
"EOF_IN_TAG": 9,
"9": "EOF_IN_TAG",
"INCORRECTLY_CLOSED_COMMENT": 10,
"10": "INCORRECTLY_CLOSED_COMMENT",
"INCORRECTLY_OPENED_COMMENT": 11,
"11": "INCORRECTLY_OPENED_COMMENT",
"INVALID_FIRST_CHARACTER_OF_TAG_NAME": 12,
"12": "INVALID_FIRST_CHARACTER_OF_TAG_NAME",
"MISSING_ATTRIBUTE_VALUE": 13,
"13": "MISSING_ATTRIBUTE_VALUE",
"MISSING_END_TAG_NAME": 14,
"14": "MISSING_END_TAG_NAME",
"MISSING_WHITESPACE_BETWEEN_ATTRIBUTES": 15,
"15": "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES",
"NESTED_COMMENT": 16,
"16": "NESTED_COMMENT",
"UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME": 17,
"17": "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME",
"UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE": 18,
"18": "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE",
"UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME": 19,
"19": "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME",
"UNEXPECTED_NULL_CHARACTER": 20,
"20": "UNEXPECTED_NULL_CHARACTER",
"UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME": 21,
"21": "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME",
"UNEXPECTED_SOLIDUS_IN_TAG": 22,
"22": "UNEXPECTED_SOLIDUS_IN_TAG",
"X_INVALID_END_TAG": 23,
"23": "X_INVALID_END_TAG",
"X_MISSING_END_TAG": 24,
"24": "X_MISSING_END_TAG",
"X_MISSING_INTERPOLATION_END": 25,
"25": "X_MISSING_INTERPOLATION_END",
"X_MISSING_DIRECTIVE_NAME": 26,
"26": "X_MISSING_DIRECTIVE_NAME",
"X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END": 27,
"27": "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END",
"X_V_IF_NO_EXPRESSION": 28,
"28": "X_V_IF_NO_EXPRESSION",
"X_V_IF_SAME_KEY": 29,
"29": "X_V_IF_SAME_KEY",
"X_V_ELSE_NO_ADJACENT_IF": 30,
"30": "X_V_ELSE_NO_ADJACENT_IF",
"X_V_FOR_NO_EXPRESSION": 31,
"31": "X_V_FOR_NO_EXPRESSION",
"X_V_FOR_MALFORMED_EXPRESSION": 32,
"32": "X_V_FOR_MALFORMED_EXPRESSION",
"X_V_FOR_TEMPLATE_KEY_PLACEMENT": 33,
"33": "X_V_FOR_TEMPLATE_KEY_PLACEMENT",
"X_V_BIND_NO_EXPRESSION": 34,
"34": "X_V_BIND_NO_EXPRESSION",
"X_V_ON_NO_EXPRESSION": 35,
"35": "X_V_ON_NO_EXPRESSION",
"X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET": 36,
"36": "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET",
"X_V_SLOT_MIXED_SLOT_USAGE": 37,
"37": "X_V_SLOT_MIXED_SLOT_USAGE",
"X_V_SLOT_DUPLICATE_SLOT_NAMES": 38,
"38": "X_V_SLOT_DUPLICATE_SLOT_NAMES",
"X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN": 39,
"39": "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN",
"X_V_SLOT_MISPLACED": 40,
"40": "X_V_SLOT_MISPLACED",
"X_V_MODEL_NO_EXPRESSION": 41,
"41": "X_V_MODEL_NO_EXPRESSION",
"X_V_MODEL_MALFORMED_EXPRESSION": 42,
"42": "X_V_MODEL_MALFORMED_EXPRESSION",
"X_V_MODEL_ON_SCOPE_VARIABLE": 43,
"43": "X_V_MODEL_ON_SCOPE_VARIABLE",
"X_V_MODEL_ON_PROPS": 44,
"44": "X_V_MODEL_ON_PROPS",
"X_INVALID_EXPRESSION": 45,
"45": "X_INVALID_EXPRESSION",
"X_KEEP_ALIVE_INVALID_CHILDREN": 46,
"46": "X_KEEP_ALIVE_INVALID_CHILDREN",
"X_PREFIX_ID_NOT_SUPPORTED": 47,
"47": "X_PREFIX_ID_NOT_SUPPORTED",
"X_MODULE_MODE_NOT_SUPPORTED": 48,
"48": "X_MODULE_MODE_NOT_SUPPORTED",
"X_CACHE_HANDLER_NOT_SUPPORTED": 49,
"49": "X_CACHE_HANDLER_NOT_SUPPORTED",
"X_SCOPE_ID_NOT_SUPPORTED": 50,
"50": "X_SCOPE_ID_NOT_SUPPORTED",
"DEPRECATION_VNODE_HOOKS": 51,
"51": "DEPRECATION_VNODE_HOOKS",
"DEPRECATION_V_IS": 52,
"52": "DEPRECATION_V_IS",
"__EXTEND_POINT__": 53,
"53": "__EXTEND_POINT__"
};
var ErrorCodes;
(function (ErrorCodes) {
// parse errors
ErrorCodes[ErrorCodes["ABRUPT_CLOSING_OF_EMPTY_COMMENT"] = 0] = "ABRUPT_CLOSING_OF_EMPTY_COMMENT";
ErrorCodes[ErrorCodes["CDATA_IN_HTML_CONTENT"] = 1] = "CDATA_IN_HTML_CONTENT";
ErrorCodes[ErrorCodes["DUPLICATE_ATTRIBUTE"] = 2] = "DUPLICATE_ATTRIBUTE";
ErrorCodes[ErrorCodes["END_TAG_WITH_ATTRIBUTES"] = 3] = "END_TAG_WITH_ATTRIBUTES";
ErrorCodes[ErrorCodes["END_TAG_WITH_TRAILING_SOLIDUS"] = 4] = "END_TAG_WITH_TRAILING_SOLIDUS";
ErrorCodes[ErrorCodes["EOF_BEFORE_TAG_NAME"] = 5] = "EOF_BEFORE_TAG_NAME";
ErrorCodes[ErrorCodes["EOF_IN_CDATA"] = 6] = "EOF_IN_CDATA";
ErrorCodes[ErrorCodes["EOF_IN_COMMENT"] = 7] = "EOF_IN_COMMENT";
ErrorCodes[ErrorCodes["EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT"] = 8] = "EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT";
ErrorCodes[ErrorCodes["EOF_IN_TAG"] = 9] = "EOF_IN_TAG";
ErrorCodes[ErrorCodes["INCORRECTLY_CLOSED_COMMENT"] = 10] = "INCORRECTLY_CLOSED_COMMENT";
ErrorCodes[ErrorCodes["INCORRECTLY_OPENED_COMMENT"] = 11] = "INCORRECTLY_OPENED_COMMENT";
ErrorCodes[ErrorCodes["INVALID_FIRST_CHARACTER_OF_TAG_NAME"] = 12] = "INVALID_FIRST_CHARACTER_OF_TAG_NAME";
ErrorCodes[ErrorCodes["MISSING_ATTRIBUTE_VALUE"] = 13] = "MISSING_ATTRIBUTE_VALUE";
ErrorCodes[ErrorCodes["MISSING_END_TAG_NAME"] = 14] = "MISSING_END_TAG_NAME";
ErrorCodes[ErrorCodes["MISSING_WHITESPACE_BETWEEN_ATTRIBUTES"] = 15] = "MISSING_WHITESPACE_BETWEEN_ATTRIBUTES";
ErrorCodes[ErrorCodes["NESTED_COMMENT"] = 16] = "NESTED_COMMENT";
ErrorCodes[ErrorCodes["UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME"] = 17] = "UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME";
ErrorCodes[ErrorCodes["UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE"] = 18] = "UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE";
ErrorCodes[ErrorCodes["UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME"] = 19] = "UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME";
ErrorCodes[ErrorCodes["UNEXPECTED_NULL_CHARACTER"] = 20] = "UNEXPECTED_NULL_CHARACTER";
ErrorCodes[ErrorCodes["UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME"] = 21] = "UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME";
ErrorCodes[ErrorCodes["UNEXPECTED_SOLIDUS_IN_TAG"] = 22] = "UNEXPECTED_SOLIDUS_IN_TAG";
// Vue-specific parse errors
ErrorCodes[ErrorCodes["X_INVALID_END_TAG"] = 23] = "X_INVALID_END_TAG";
ErrorCodes[ErrorCodes["X_MISSING_END_TAG"] = 24] = "X_MISSING_END_TAG";
ErrorCodes[ErrorCodes["X_MISSING_INTERPOLATION_END"] = 25] = "X_MISSING_INTERPOLATION_END";
ErrorCodes[ErrorCodes["X_MISSING_DIRECTIVE_NAME"] = 26] = "X_MISSING_DIRECTIVE_NAME";
ErrorCodes[ErrorCodes["X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END"] = 27] = "X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END";
// transform errors
ErrorCodes[ErrorCodes["X_V_IF_NO_EXPRESSION"] = 28] = "X_V_IF_NO_EXPRESSION";
ErrorCodes[ErrorCodes["X_V_IF_SAME_KEY"] = 29] = "X_V_IF_SAME_KEY";
ErrorCodes[ErrorCodes["X_V_ELSE_NO_ADJACENT_IF"] = 30] = "X_V_ELSE_NO_ADJACENT_IF";
ErrorCodes[ErrorCodes["X_V_FOR_NO_EXPRESSION"] = 31] = "X_V_FOR_NO_EXPRESSION";
ErrorCodes[ErrorCodes["X_V_FOR_MALFORMED_EXPRESSION"] = 32] = "X_V_FOR_MALFORMED_EXPRESSION";
ErrorCodes[ErrorCodes["X_V_FOR_TEMPLATE_KEY_PLACEMENT"] = 33] = "X_V_FOR_TEMPLATE_KEY_PLACEMENT";
ErrorCodes[ErrorCodes["X_V_BIND_NO_EXPRESSION"] = 34] = "X_V_BIND_NO_EXPRESSION";
ErrorCodes[ErrorCodes["X_V_ON_NO_EXPRESSION"] = 35] = "X_V_ON_NO_EXPRESSION";
ErrorCodes[ErrorCodes["X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET"] = 36] = "X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET";
ErrorCodes[ErrorCodes["X_V_SLOT_MIXED_SLOT_USAGE"] = 37] = "X_V_SLOT_MIXED_SLOT_USAGE";
ErrorCodes[ErrorCodes["X_V_SLOT_DUPLICATE_SLOT_NAMES"] = 38] = "X_V_SLOT_DUPLICATE_SLOT_NAMES";
ErrorCodes[ErrorCodes["X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN"] = 39] = "X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN";
ErrorCodes[ErrorCodes["X_V_SLOT_MISPLACED"] = 40] = "X_V_SLOT_MISPLACED";
ErrorCodes[ErrorCodes["X_V_MODEL_NO_EXPRESSION"] = 41] = "X_V_MODEL_NO_EXPRESSION";
ErrorCodes[ErrorCodes["X_V_MODEL_MALFORMED_EXPRESSION"] = 42] = "X_V_MODEL_MALFORMED_EXPRESSION";
ErrorCodes[ErrorCodes["X_V_MODEL_ON_SCOPE_VARIABLE"] = 43] = "X_V_MODEL_ON_SCOPE_VARIABLE";
ErrorCodes[ErrorCodes["X_V_MODEL_ON_PROPS"] = 44] = "X_V_MODEL_ON_PROPS";
ErrorCodes[ErrorCodes["X_INVALID_EXPRESSION"] = 45] = "X_INVALID_EXPRESSION";
ErrorCodes[ErrorCodes["X_KEEP_ALIVE_INVALID_CHILDREN"] = 46] = "X_KEEP_ALIVE_INVALID_CHILDREN";
// generic errors
ErrorCodes[ErrorCodes["X_PREFIX_ID_NOT_SUPPORTED"] = 47] = "X_PREFIX_ID_NOT_SUPPORTED";
ErrorCodes[ErrorCodes["X_MODULE_MODE_NOT_SUPPORTED"] = 48] = "X_MODULE_MODE_NOT_SUPPORTED";
ErrorCodes[ErrorCodes["X_CACHE_HANDLER_NOT_SUPPORTED"] = 49] = "X_CACHE_HANDLER_NOT_SUPPORTED";
ErrorCodes[ErrorCodes["X_SCOPE_ID_NOT_SUPPORTED"] = 50] = "X_SCOPE_ID_NOT_SUPPORTED";
// deprecations
ErrorCodes[ErrorCodes["DEPRECATION_VNODE_HOOKS"] = 51] = "DEPRECATION_VNODE_HOOKS";
ErrorCodes[ErrorCodes["DEPRECATION_V_IS"] = 52] = "DEPRECATION_V_IS";
// Special value for higher-order compilers to pick up the last code
// to avoid collision of error codes. This should always be kept as the last
// item.
ErrorCodes[ErrorCodes["__EXTEND_POINT__"] = 53] = "__EXTEND_POINT__";
})(ErrorCodes || (ErrorCodes = {}));
console.log(ErrorCodesObject.ABRUPT_CLOSING_OF_EMPTY_COMMENT)
console.log(ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT) Then you can see result var _;!function(_){_[_.ABRUPT_CLOSING_OF_EMPTY_COMMENT=0]="ABRUPT_CLOSING_OF_EMPTY_COMMENT",
// more than 3KiB size of code here
}(_||(_={})),
console.log(0),
console.log(_.ABRUPT_CLOSING_OF_EMPTY_COMMENT); If some application user use enum export in vue, it will increase many size. |
I'm not sure if bundler and minifier can handle it perfectly (cross module boundary). But yeah, I get the idea. |
9992964
to
034a05e
Compare
Done. |
LGTM |
9e90927
to
953b21a
Compare
533cfa9
to
7f1c6c7
Compare
Should we always export enums? The bundle size of the browser version increased ~750b |
7f1c6c7
to
b84dca5
Compare
07c6b95
to
48ce2e2
Compare
66118a2
to
bd3abc0
Compare
bde29fb
to
4c5608e
Compare
4c5608e
to
5b7e56b
Compare
5b7e56b
to
6da9c7e
Compare
const enum
toenum