8000 avoid implicit reference to global variables (fix #2297) · codeclever/vue@8419d8c · GitHub
[go: up one dir, main page]

Skip to content

Commit 8419d8c

Browse files
committed
avoid implicit reference to global variables (fix vuejs#2297)
1 parent 8bc8580 commit 8419d8c

File tree

6 files changed

+32
-23
lines changed

6 files changed

+32
-23
lines changed

src/compiler/transclude.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
33
import {
44
warn,
55
isTemplate,
6+
isFragment,
67
prepend,
78
extractContent,
89
createAnchor,
@@ -49,7 +50,7 @@ export function transclude (el, options) {
4950
el = transcludeTemplate(el, options)
5051
}
5152
}
52-
if (el instanceof DocumentFragment) {
53+
if (isFragment(el)) {
5354
// anchors for fragment instance
5455
// passing in `persist: true` to avoid them being
5556
// discarded by IE during template cloning

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if (devtools) {
3333
devtools.emit('init', Vue)
3434
} else if (
3535
process.env.NODE_ENV !== 'production' &&
36-
inBrowser && /Chrome\/\d+/.test(navigator.userAgent)
36+
inBrowser && /Chrome\/\d+/.test(window.navigator.userAgent)
3737
) {
3838
console.log(
3939
'Download the Vue Devtools for a better development experience:\n' +

src/instance/internal/lifecycle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { replace, getAttr } from '../../util/index'
21
import Directive from '../../directive'
2+
import { replace, getAttr, isFragment } from '../../util/index'
33
import { compile, compileRoot, transclude } from '../../compiler/index'
44

55
export default function (Vue) {
@@ -103,7 +103,7 @@ export default function (Vue) {
103103
*/
104104

105105
Vue.prototype._initElement = function (el) {
106-
if (el instanceof DocumentFragment) {
106+
if (isFragment(el)) {
107107
this._isFragment = true
108108
this.$el = this._fragmentStart = el.firstChild
109109
this._fragmentEnd = el.lastChild

src/parsers/template.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import { inBrowser, trimNode, isTemplate } from '../util/index'
21
import Cache from '../cache'
2+
import {
3+
inBrowser,
4+
trimNode,
5+
isTemplate,
6+
isFragment
7+
} from '../util/index'
38

49
const templateCache = new Cache(1000)
510
const idSelectorCache = new Cache(1000)
@@ -66,8 +71,7 @@ map.rect = [
6671
*/
6772

6873
function isRealTemplate (node) {
69-
return isTemplate(node) &&
70-
node.content instanceof DocumentFragment
74+
return isTemplate(node) && isFragment(node.content)
7175
}
7276

7377
const tagRE = /<([\w:]+)/
@@ -262,7 +266,7 @@ export function parseTemplate (template, shouldClone, raw) {
262266

263267
// if the template is already a document fragment,
264268
// do nothing
265-
if (template instanceof DocumentFragment) {
269+
if (isFragment(template)) {
266270
trimNode(template)
267271
return shouldClone
268272
? cloneNode(template)

src/util/dom.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export function off (el, event, cb) {
191191

192192
export function setClass (el, cls) {
193193
/* istanbul ignore if */
194-
if (isIE9 && !(el instanceof SVGElement)) {
194+
if (isIE9 && !/svg$/.test(el.namespaceURI)) {
195195
el.className = cls
196196
} else {
197197
el.setAttribute('class', cls)
@@ -252,10 +252,7 @@ export function extractContent (el, asFragment) {
252252
var child
253253
var rawContent
254254
/* istanbul ignore if */
255-
if (
256-
isTemplate(el) &&
257-
el.content instanceof DocumentFragment
258-
) {
255+
if (isTemplate(el) && isFragment(el.content)) {
259256
el = el.content
260257
}
261258
if (el.hasChildNodes()) {
@@ -406,3 +403,14 @@ export function removeNodeRange (start, end, vm, frag, cb) {
406403
}
407404
}
408405
}
406+
407+
/**
408+
* Check if a node is a DocumentFragment.
409+
*
410+
* @param {Node} node
411+
* @return {Boolean}
412+
*/
413+
414+
export function isFragment (node) {
415+
return node && node.nodeType === 11
416+
}

src/util/env.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ export const inBrowser =
66
typeof window !== 'undefined' &&
77
Object.prototype.toString.call(window) !== '[object Object]'
88

9-
export const devtools =
10-
inBrowser &&
11-
window.__VUE_DEVTOOLS_GLOBAL_HOOK__
9+
// detect devtools
10+
export const devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__
1211

13-
export const isIE9 =
14-
inBrowser &&
15-
navigator.userAgent.toLowerCase().indexOf('msie 9.0') > 0
16-
17-
export const isAndroid =
18-
inBrowser &&
19-
navigator.userAgent.toLowerCase().indexOf('android') > 0
12+
// UA sniffing for working around browser-specific quirks
13+
const UA = inBrowser && window.navigator.userAgent.toLowerCase()
14+
export const isIE9 = UA && UA.indexOf('msie 9.0') > 0
15+
export const isAndroid = UA && UA.indexOf('android') > 0
2016

2117
let transitionProp
2218
let transitionEndEvent

0 commit comments

Comments
 (0)
0