Skip to content

Commit 80bf5d6

Browse files
committed
rearrange util functions so ones unused in runtime build can be dropped by uglify
1 parent 61f7d0d commit 80bf5d6

File tree

9 files changed

+71
-68
lines changed

9 files changed

+71
-68
lines changed

src/compiler/parser/html-parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
import { makeMap, no } from 'shared/util'
13-
import { isNonPhrasingTag, canBeLeftOpenTag } from 'web/util/index'
13+
import { isNonPhrasingTag, canBeLeftOpenTag } from 'web/compiler/util'
1414

1515
// Regular Expressions for parsing tags and attributes
1616
const singleAttrIdentifier = /([^\s"'<>/=]+)/

src/core/instance/state.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import {
1818
isPlainObject,
1919
bind,
2020
validateProp,
21-
noop,
22-
makeMap
21+
noop
2322
} from '../util/index'
2423

2524
export function initState (vm: Component) {
@@ -31,7 +30,7 @@ export function initState (vm: Component) {
3130
initWatch(vm)
3231
}
3332

34-
const isReservedProp = makeMap('key,ref,slot')
33+
const isReservedProp = { key: 1, ref: 1, slot: 1 }
3534

3635
function initProps (vm: Component) {
3736
const props = vm.$options.props
@@ -45,7 +44,7 @@ function initProps (vm: Component) {
4544
const key = keys[i]
4645
/* istanbul ignore else */
4746
if (process.env.NODE_ENV !== 'production') {
48-
if (isReservedProp(key)) {
47+
if (isReservedProp[key]) {
4948
warn(
5049
`"${key}" is a reserved attribute and cannot be used as component prop.`,
5150
vm

src/entries/web-server-renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ process.env.VUE_ENV = 'server'
44

55
import { createRenderer as _createRenderer } from 'server/create-renderer'
66
import { createBundleRendererCreator } from 'server/create-bundle-renderer'
7-
import { isUnaryTag } from 'web/util/index'
7+
import { isUnaryTag } from 'web/compiler/util'
88
import modules from 'web/server/modules/index'
99
import baseDirectives from 'web/server/directives/index'
1010

src/platforms/web/compiler/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import { compile as baseCompile } from 'compiler/index'
66
import { detectErrors } from 'compiler/error-detector'
77
import modules from './modules/index'
88
import directives from './directives/index'
9-
import {
10-
isReservedTag, isUnaryTag,
11-
mustUseProp, getTagNamespace, isPreTag
12-
} from '../util/index'
9+
import { isReservedTag, mustUseProp, getTagNamespace, isPreTag } from '../util/index'
10+
import { isUnaryTag } from './util'
1311

1412
const cache: { [key: string]: CompiledFunctionResult } = Object.create(null)
1513

src/platforms/web/compiler/util.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* @flow */
2+
3+
import { makeMap } from 'shared/util'
4+
5+
export const isUnaryTag = makeMap(
6+
'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
7+
'link,meta,param,source,track,wbr',
8+
true
9+
)
10+
11+
// Elements that you can, intentionally, leave open
12+
// (and which close themselves)
13+
export const canBeLeftOpenTag = makeMap(
14+
'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source',
15+
true
16+
)
17+
18+
// HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
19+
// Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
20+
export const isNonPhrasingTag = makeMap(
21+
'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +
22+
'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +
23+
'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +
24+
'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +
25+
'title,tr,track',
26+
true
27+
)

src/platforms/web/server/modules/dom-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import VNode from 'core/vdom/vnode'
44
import { renderAttr } from './attrs'
5-
import { propsToAttrMap, isRenderableAttr } from 'web/util/attrs'
5+
import { propsToAttrMap, isRenderableAttr } from '../util'
66

77
export default function renderDOMProps (node: VNodeWithData): string {
88
let props = node.data.domProps

src/platforms/web/server/util.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* @flow */
2+
3+
import { makeMap } from 'shared/util'
4+
5+
const isAttr = makeMap(
6+
'accept,accept-charset,accesskey,action,align,alt,async,autocomplete,' +
7+
'autofocus,autoplay,autosave,bgcolor,border,buffered,challenge,charset,' +
8+
'checked,cite,class,code,codebase,color,cols,colspan,content,http-equiv,' +
9+
'name,contenteditable,contextmenu,controls,coords,data,datetime,default,' +
10+
'defer,dir,dirname,disabled,download,draggable,dropzone,enctype,method,for,' +
11+
'form,formaction,headers,<th>,height,hidden,high,href,hreflang,http-equiv,' +
12+
'icon,id,ismap,itemprop,keytype,kind,label,lang,language,list,loop,low,' +
13+
'manifest,max,maxlength,media,method,GET,POST,min,multiple,email,file,' +
14+
'muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,' +
15+
'preload,radiogroup,readonly,rel,required,reversed,rows,rowspan,sandbox,' +
16+
'scope,scoped,seamless,selected,shape,size,type,text,password,sizes,span,' +
17+
'spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,' +
18+
'target,title,type,usemap,value,width,wrap'
19+
)
20+
21+
/* istanbul ignore next */
22+
const isRenderableAttr = (name: string): boolean => {
23+
return (
24+
isAttr(name) ||
25+
name.indexOf('data-') === 0 ||
26+
name.indexOf('aria-') === 0
27+
)
28+
}
29+
export { isRenderableAttr }
30+
31+
export const propsToAttrMap = {
32+
acceptCharset: 'accept-charset',
33+
className: 'class',
34+
htmlFor: 'for',
35+
httpEquiv: 'http-equiv'
36+
}

src/platforms/web/util/attrs.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,6 @@ export const isBooleanAttr = makeMap(
2323
'truespeed,typemustmatch,visible'
2424
)
2525

26-
const isAttr = makeMap(
27-
'accept,accept-charset,accesskey,action,align,alt,async,autocomplete,' +
28-
'autofocus,autoplay,autosave,bgcolor,border,buffered,challenge,charset,' +
29-
'checked,cite,class,code,codebase,color,cols,colspan,content,http-equiv,' +
30-
'name,contenteditable,contextmenu,controls,coords,data,datetime,default,' +
31-
'defer,dir,dirname,disabled,download,draggable,dropzone,enctype,method,for,' +
32-
'form,formaction,headers,<th>,height,hidden,high,href,hreflang,http-equiv,' +
33-
'icon,id,ismap,itemprop,keytype,kind,label,lang,language,list,loop,low,' +
34-
'manifest,max,maxlength,media,method,GET,POST,min,multiple,email,file,' +
35-
'muted,name,novalidate,open,optimum,pattern,ping,placeholder,poster,' +
36-
'preload,radiogroup,readonly,rel,required,reversed,rows,rowspan,sandbox,' +
37-
'scope,scoped,seamless,selected,shape,size,type,text,password,sizes,span,' +
38-
'spellcheck,src,srcdoc,srclang,srcset,start,step,style,summary,tabindex,' +
39-
'target,title,type,usemap,value,width,wrap'
40-
)
41-
42-
/* istanbul ignore next */
43-
const isRenderableAttr = (name: string): boolean => {
44-
return (
45-
isAttr(name) ||
46-
name.indexOf('data-') === 0 ||
47-
name.indexOf('aria-') === 0
48-
)
49-
}
50-
export { isRenderableAttr }
51-
52-
export const propsToAttrMap = {
53-
acceptCharset: 'accept-charset',
54-
className: 'class',
55-
htmlFor: 'for',
56-
httpEquiv: 'http-equiv'
57-
}
58-
5926
export const xlinkNS = 'http://www.w3.org/1999/xlink'
6027

6128
export const isXlink = (name: string): boolean => {

src/platforms/web/util/element.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,6 @@ export const isHTMLTag = makeMap(
2323
'content,element,shadow,template'
2424
)
2525

26-
export const isUnaryTag = makeMap(
27-
'area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' +
28-
'link,meta,param,source,track,wbr',
29-
true
30-
)
31-
32-
// Elements that you can, intentionally, leave open
33-
// (and which close themselves)
34-
export const canBeLeftOpenTag = makeMap(
35-
'colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr,source',
36-
true
37-
)
38-
39-
// HTML5 tags https://html.spec.whatwg.org/multipage/indices.html#elements-3
40-
// Phrasing Content https://html.spec.whatwg.org/multipage/dom.html#phrasing-content
41-
export const isNonPhrasingTag = makeMap(
42-
'address,article,aside,base,blockquote,body,caption,col,colgroup,dd,' +
43-
'details,dialog,div,dl,dt,fieldset,figcaption,figure,footer,form,' +
44-
'h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,legend,li,menuitem,meta,' +
45-
'optgroup,option,param,rp,rt,source,style,summary,tbody,td,tfoot,th,thead,' +
46-
'title,tr,track',
47-
true
48-
)
49-
5026
// this map is intentionally selective, only covering SVG elements that may
5127
// contain child elements.
5228
export const isSVG = makeMap(

0 commit comments

Comments
 (0)