Skip to content

Commit

Permalink
chore: use __NO_SIDE_EFFECTS__ to replace __PURE__
Browse files Browse the repository at this point in the history
  • Loading branch information
chenfan0 committed Aug 31, 2023
1 parent 2ffe3d5 commit 7ce8b15
Show file tree
Hide file tree
Showing 21 changed files with 49 additions and 53 deletions.
4 changes: 1 addition & 3 deletions packages/compiler-core/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,7 @@ const enum TagType {
End
}

const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(
`if,else,else-if,for,slot`
)
const isSpecialTemplateDirective = makeMap(`if,else,else-if,for,slot`)

/**
* Parse a tag (E.g. `<div id=a>`) with that type (start tag or end tag).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { parse } from '@babel/parser'
import { IS_REF, UNREF } from '../runtimeHelpers'
import { BindingTypes } from '../options'

const isLiteralWhitelisted = /*#__PURE__*/ makeMap('true,false,null,this')
const isLiteralWhitelisted = makeMap('true,false,null,this')

// a heuristic safeguard to bail constant expressions on presence of
// likely function invocation and member access
Expand Down
5 changes: 1 addition & 4 deletions packages/compiler-dom/src/parserOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { TRANSITION, TRANSITION_GROUP } from './runtimeHelpers'
import { decodeHtml } from './decodeHtml'
import { decodeHtmlBrowser } from './decodeHtmlBrowser'

const isRawTextContainer = /*#__PURE__*/ makeMap(
'style,iframe,script,noscript',
true
)
const isRawTextContainer = makeMap('style,iframe,script,noscript', true)

export const enum DOMNamespaces {
HTML = 0 /* Namespaces.HTML */,
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 @@ -167,7 +167,7 @@ const replaceHoist = (
context.hoists[context.hoists.indexOf(hoistToReplace)] = replacement
}

const isNonStringifiable = /*#__PURE__*/ makeMap(
const isNonStringifiable = makeMap(
`caption,thead,tr,th,tbody,td,tfoot,colgroup,col`
)

Expand Down
11 changes: 4 additions & 7 deletions packages/compiler-dom/src/transforms/vOn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
import { V_ON_WITH_MODIFIERS, V_ON_WITH_KEYS } from '../runtimeHelpers'
import { makeMap, capitalize } from '@vue/shared'

const isEventOptionModifier = /*#__PURE__*/ makeMap(`passive,once,capture`)
const isNonKeyModifier = /*#__PURE__*/ makeMap(
const isEventOptionModifier = makeMap(`passive,once,capture`)
const isNonKeyModifier = makeMap(
// event propagation management
`stop,prevent,self,` +
// system modifiers + exact
Expand All @@ -27,11 +27,8 @@ const isNonKeyModifier = /*#__PURE__*/ makeMap(
`middle`
)
// left & right could be mouse or key modifiers based on event type
const maybeKeyModifier = /*#__PURE__*/ makeMap('left,right')
const isKeyboardEvent = /*#__PURE__*/ makeMap(
`onkeyup,onkeydown,onkeypress`,
true
)
const maybeKeyModifier = makeMap('left,right')
const isKeyboardEvent = makeMap(`onkeyup,onkeydown,onkeypress`, true)

const resolveModifiers = (
key: ExpressionNode,
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/src/baseHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import { isRef } from './ref'
import { warn } from './warning'

const isNonTrackableKeys = /*#__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`)
const isNonTrackableKeys = makeMap(`__proto__,__v_isRef,__isVue`)

const builtInSymbols = new Set(
/*#__PURE__*/
Expand Down
9 changes: 5 additions & 4 deletions packages/reactivity/src/collectionHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ const [
shallowReadonlyInstrumentations
] = /* #__PURE__*/ createInstrumentations()

/*! #__NO_SIDE_EFFECTS__ */
function createInstrumentationGetter(isReadonly: boolean, shallow: boolean) {
const instrumentations = shallow
? isReadonly
Expand Down Expand Up @@ -364,20 +365,20 @@ function createInstrumentationGetter(isReadonly: boolean, shallow: boolean) {
}

export const mutableCollectionHandlers: ProxyHandler<CollectionTypes> = {
get: /*#__PURE__*/ createInstrumentationGetter(false, false)
get: createInstrumentationGetter(false, false)
}

export const shallowCollectionHandlers: ProxyHandler<CollectionTypes> = {
get: /*#__PURE__*/ createInstrumentationGetter(false, true)
get: createInstrumentationGetter(false, true)
}

export const readonlyCollectionHandlers: ProxyHandler<CollectionTypes> = {
get: /*#__PURE__*/ createInstrumentationGetter(true, false)
get: createInstrumentationGetter(true, false)
}

export const shallowReadonlyCollectionHandlers: ProxyHandler<CollectionTypes> =
{
get: /*#__PURE__*/ createInstrumentationGetter(true, true)
get: createInstrumentationGetter(true, true)
}

function checkIdentityKeys(
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/compat/renderFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function compatH(
}
}

const skipLegacyRootLevelProps = /*#__PURE__*/ makeMap(
const skipLegacyRootLevelProps = makeMap(
'staticStyle,staticClass,directives,model,hook'
)

Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ export const unsetCurrentInstance = () => {
internalSetCurrentInstance(null)
}

const isBuiltInTag = /*#__PURE__*/ makeMap('slot,component')
const isBuiltInTag = makeMap('slot,component')

export function validateComponentName(name: string, config: AppConfig) {
const appIsNativeTag = config.isNativeTag || NO
Expand Down
4 changes: 1 addition & 3 deletions packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,7 @@ function validateProp(
}
}

const isSimpleType = /*#__PURE__*/ makeMap(
'String,Number,Boolean,Function,Symbol,BigInt'
)
const isSimpleType = makeMap('String,Number,Boolean,Function,Symbol,BigInt')

type AssertionResult = {
valid: boolean
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/componentPublicInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ const getPublicInstance = (
export const publicPropertiesMap: PublicPropertiesMap =
// Move PURE marker to new line to workaround compiler discarding it
// due to type annotation
/*#__PURE__*/ extend(Object.create(null), {
extend(Object.create(null), {
$: i => i,
$el: i => i.vnode.el,
$data: i => i.data,
Expand Down Expand Up @@ -499,7 +499,7 @@ if (__DEV__ && !__TEST__) {
}
}

export const RuntimeCompiledPublicInstanceProxyHandlers = /*#__PURE__*/ extend(
export const RuntimeCompiledPublicInstanceProxyHandlers = extend(
{},
PublicInstanceProxyHandlers,
{
Expand Down
15 changes: 9 additions & 6 deletions packages/runtime-core/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ export function devtoolsUnmountApp(app: App) {
emit(DevtoolsHooks.APP_UNMOUNT, app)
}

export const devtoolsComponentAdded = /*#__PURE__*/ createDevtoolsComponentHook(
export const devtoolsComponentAdded = createDevtoolsComponentHook(
DevtoolsHooks.COMPONENT_ADDED
)

export const devtoolsComponentUpdated =
/*#__PURE__*/ createDevtoolsComponentHook(DevtoolsHooks.COMPONENT_UPDATED)
export const devtoolsComponentUpdated = createDevtoolsComponentHook(
DevtoolsHooks.COMPONENT_UPDATED
)

const _devtoolsComponentRemoved = /*#__PURE__*/ createDevtoolsComponentHook(
const _devtoolsComponentRemoved = createDevtoolsComponentHook(
DevtoolsHooks.COMPONENT_REMOVED
)

Expand All @@ -123,6 +124,7 @@ export const devtoolsComponentRemoved = (
}
}

/*! #__NO_SIDE_EFFECTS__ */
function createDevtoolsComponentHook(hook: DevtoolsHooks) {
return (component: ComponentInternalInstance) => {
emit(
Expand All @@ -135,14 +137,15 @@ function createDevtoolsComponentHook(hook: DevtoolsHooks) {
}
}

export const devtoolsPerfStart = /*#__PURE__*/ createDevtoolsPerformanceHook(
export const devtoolsPerfStart = createDevtoolsPerformanceHook(
DevtoolsHooks.PERFORMANCE_START
)

export const devtoolsPerfEnd = /*#__PURE__*/ createDevtoolsPerformanceHook(
export const devtoolsPerfEnd = createDevtoolsPerformanceHook(
DevtoolsHooks.PERFORMANCE_END
)

/*! #__NO_SIDE_EFFECTS__ */
function createDevtoolsPerformanceHook(hook: DevtoolsHooks) {
return (component: ComponentInternalInstance, type: string, time: number) => {
emit(hook, component.appContext.app, component.uid, component, type, time)
Expand Down
11 changes: 5 additions & 6 deletions packages/runtime-dom/src/components/Transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ const DOMTransitionPropsValidators = {
leaveToClass: String
}

export const TransitionPropsValidators = (Transition.props =
/*#__PURE__*/ extend(
{},
BaseTransitionPropsValidators as any,
DOMTransitionPropsValidators
))
export const TransitionPropsValidators = (Transition.props = extend(
{},
BaseTransitionPropsValidators as any,
DOMTransitionPropsValidators
))

/**
* #3227 Incoming hooks may be merged into arrays when wrapping Transition
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-dom/src/components/TransitionGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type TransitionGroupProps = Omit<TransitionProps, 'mode'> & {
const TransitionGroupImpl: ComponentOptions = {
name: 'TransitionGroup',

props: /*#__PURE__*/ extend({}, TransitionPropsValidators, {
props: extend({}, TransitionPropsValidators, {
tag: String,
moveClass: String
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ declare module '@vue/reactivity' {
}
}

const rendererOptions = /*#__PURE__*/ extend({ patchProp }, nodeOps)
const rendererOptions = extend({ patchProp }, nodeOps)

// lazy create the renderer - this makes core renderer logic tree-shakable
// in case the user only imports reactivity utilities from Vue.
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-dom/src/modules/attrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function patchAttr(

// 2.x compat
const isEnumeratedAttr = __COMPAT__
? /*#__PURE__*/ makeMap('contenteditable,draggable,spellcheck')
? makeMap('contenteditable,draggable,spellcheck')
: NOOP

export function compatCoerceAttr(
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/src/domAttrConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { makeMap } from './makeMap'
* - readonly -> readOnly
*/
const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`
export const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs)
export const isSpecialBooleanAttr = makeMap(specialBooleanAttrs)

/**
* The full list is needed during SSR to produce the correct initial markup.
*/
export const isBooleanAttr = /*#__PURE__*/ makeMap(
export const isBooleanAttr = makeMap(
specialBooleanAttrs +
`,async,autofocus,autoplay,controls,default,defer,disabled,hidden,` +
`inert,loop,open,required,reversed,scoped,seamless,` +
Expand Down Expand Up @@ -59,7 +59,7 @@ export const propsToAttrMap: Record<string, string | undefined> = {
* Don't also forget to allow `data-*` and `aria-*`!
* Generated from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
*/
export const isKnownHtmlAttr = /*#__PURE__*/ makeMap(
export const isKnownHtmlAttr = makeMap(
`accept,accept-charset,accesskey,action,align,allow,alt,async,` +
`autocapitalize,autocomplete,autofocus,autoplay,background,bgcolor,` +
`border,buffered,capture,challenge,charset,checked,cite,class,code,` +
Expand All @@ -80,7 +80,7 @@ export const isKnownHtmlAttr = /*#__PURE__*/ makeMap(
/**
* Generated from https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute
*/
export const isKnownSvgAttr = /*#__PURE__*/ makeMap(
export const isKnownSvgAttr = makeMap(
`xmlns,accent-height,accumulate,additive,alignment-baseline,alphabetic,amplitude,` +
`arabic-form,ascent,attributeName,attributeType,azimuth,baseFrequency,` +
`baseline-shift,baseProfile,bbox,begin,bias,by,calcMode,cap-height,class,` +
Expand Down
6 changes: 3 additions & 3 deletions packages/shared/src/domTagConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ const VOID_TAGS =
* Compiler only.
* Do NOT use in runtime code paths unless behind `__DEV__` flag.
*/
export const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS)
export const isHTMLTag = makeMap(HTML_TAGS)
/**
* Compiler only.
* Do NOT use in runtime code paths unless behind `__DEV__` flag.
*/
export const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS)
export const isSVGTag = makeMap(SVG_TAGS)
/**
* Compiler only.
* Do NOT use in runtime code paths unless behind `__DEV__` flag.
*/
export const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS)
export const isVoidTag = makeMap(VOID_TAGS)
5 changes: 3 additions & 2 deletions packages/shared/src/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const isOn = (key: string) => onRE.test(key)

export const isModelListener = (key: string) => key.startsWith('onUpdate:')

/*! #__NO_SIDE_EFFECTS__ */
export const extend = Object.assign

export const remove = <T>(arr: T[], el: T) => {
Expand Down Expand Up @@ -75,15 +76,15 @@ export const isIntegerKey = (key: unknown) =>
key[0] !== '-' &&
'' + parseInt(key, 10) === key

export const isReservedProp = /*#__PURE__*/ makeMap(
export const isReservedProp = makeMap(
// the leading comma is intentional so empty string "" is also included
',key,ref,ref_for,ref_key,' +
'onVnodeBeforeMount,onVnodeMounted,' +
'onVnodeBeforeUpdate,onVnodeUpdated,' +
'onVnodeBeforeUnmount,onVnodeUnmounted'
)

export const isBuiltInDirective = /*#__PURE__*/ makeMap(
export const isBuiltInDirective = makeMap(
'bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo'
)

Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/globalsAllowList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const GLOBALS_ALLOWED =
'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console'

export const isGloballyAllowed = /*#__PURE__*/ makeMap(GLOBALS_ALLOWED)
export const isGloballyAllowed = makeMap(GLOBALS_ALLOWED)

/** @deprecated use `isGloballyAllowed` instead */
export const isGloballyWhitelisted = isGloballyAllowed
2 changes: 2 additions & 0 deletions packages/shared/src/makeMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* \/\*#\_\_PURE\_\_\*\/
* So that rollup can tree-shake them if necessary.
*/

/*! #__NO_SIDE_EFFECTS__ */
export function makeMap(
str: string,
expectsLowerCase?: boolean
Expand Down

0 comments on commit 7ce8b15

Please sign in to comment.