Skip to content

Commit d3a9a50

Browse files
committed
1 parent 80a7cea commit d3a9a50

File tree

4 files changed

+1620
-1590
lines changed

4 files changed

+1620
-1590
lines changed

packages/weex-template-compiler/build.js

Lines changed: 25 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ var isBuiltInTag = makeMap('slot,component', true);
4545
*/
4646

4747

48-
/**
49-
* Check whether the object has the property.
50-
*/
51-
var hasOwnProperty = Object.prototype.hasOwnProperty;
5248

5349

5450
/**
@@ -68,7 +64,7 @@ function cached (fn) {
6864
}
6965

7066
/**
71-
* Camelize a hyphen-delmited string.
67+
* Camelize a hyphen-delimited string.
7268
*/
7369
var camelizeRE = /-(\w)/g;
7470
var camelize = cached(function (str) {
@@ -80,10 +76,6 @@ var camelize = cached(function (str) {
8076
*/
8177

8278

83-
/**
84-
* Hyphenate a camelCase string.
85-
*/
86-
var hyphenateRE = /([^-])([A-Z])/g;
8779

8880

8981
/**
@@ -113,12 +105,6 @@ function extend (to, _from) {
113105
*/
114106

115107

116-
/**
117-
* Strict object type check. Only returns true
118-
* for plain JavaScript objects.
119-
*/
120-
var toString = Object.prototype.toString;
121-
var OBJECT_STRING = '[object Object]';
122108

123109

124110
/**
@@ -354,22 +340,6 @@ var IS_REGEX_CAPTURING_BROKEN = false;
354340

355341
// Special Elements (can contain anything)
356342
var isScriptOrStyle = makeMap('script,style', true);
357-
var hasLang = function (attr) { return attr.name === 'lang' && attr.value !== 'html'; };
358-
var isSpecialTag = function (tag, isSFC, stack) {
359-
if (isScriptOrStyle(tag)) {
360-
return true
361-
}
362-
if (isSFC && stack.length === 1) {
363-
// top-level template that has no pre-processor
364-
if (tag === 'template' && !stack[0].attrs.some(hasLang)) {
365-
return false
366-
} else {
367-
return true
368-
}
369-
}
370-
return false
371-
};
372-
373343
var reCache = {};
374344

375345
var ltRE = /</g;
@@ -398,7 +368,7 @@ function parseHTML (html, options) {
398368
while (html) {
399369
last = html;
400370
// Make sure we're not in a script or style element
401-
if (!lastTag || !isSpecialTag(lastTag, options.sfc, stack)) {
371+
if (!lastTag || !isScriptOrStyle(lastTag)) {
402372
var textEnd = html.indexOf('<');
403373
if (textEnd === 0) {
404374
// Comment:
@@ -433,7 +403,7 @@ function parseHTML (html, options) {
433403
if (endTagMatch) {
434404
var curIndex = index;
435405
advance(endTagMatch[0].length);
436-
parseEndTag(endTagMatch[0], endTagMatch[1], curIndex, index);
406+
parseEndTag(endTagMatch[1], curIndex, index);
437407
continue
438408
}
439409

@@ -490,7 +460,7 @@ function parseHTML (html, options) {
490460
});
491461
index += html.length - rest.length;
492462
html = rest;
493-
parseEndTag('</' + stackedTag + '>', stackedTag, index - endTagLength, index);
463+
parseEndTag(stackedTag, index - endTagLength, index);
494464
}
495465

496466
if (html === last && options.chars) {
@@ -536,10 +506,10 @@ function parseHTML (html, options) {
536506

537507
if (expectHTML) {
538508
if (lastTag === 'p' && isNonPhrasingTag(tagName)) {
539-
parseEndTag('', lastTag);
509+
parseEndTag(lastTag);
540510
}
541511
if (canBeLeftOpenTag(tagName) && lastTag === tagName) {
542-
parseEndTag('', tagName);
512+
parseEndTag(tagName);
543513
}
544514
}
545515

@@ -566,7 +536,7 @@ function parseHTML (html, options) {
566536
}
567537

568538
if (!unary) {
569-
stack.push({ tag: tagName, attrs: attrs });
539+
stack.push({ tag: tagName, lowerCasedTag: tagName.toLowerCase(), attrs: attrs });
570540
lastTag = tagName;
571541
unarySlash = '';
572542
}
@@ -576,16 +546,19 @@ function parseHTML (html, options) {
576546
}
577547
}
578548

579-
function parseEndTag (tag, tagName, start, end) {
580-
var pos;
549+
function parseEndTag (tagName, start, end) {
550+
var pos, lowerCasedTagName;
581551
if (start == null) { start = index; }
582552
if (end == null) { end = index; }
583553

554+
if (tagName) {
555+
lowerCasedTagName = tagName.toLowerCase();
556+
}
557+
584558
// Find the closest opened tag of the same type
585559
if (tagName) {
586-
var needle = tagName.toLowerCase();
587560
for (pos = stack.length - 1; pos >= 0; pos--) {
588-
if (stack[pos].tag.toLowerCase() === needle) {
561+
if (stack[pos].lowerCasedTag === lowerCasedTagName) {
589562
break
590563
}
591564
}
@@ -605,11 +578,11 @@ function parseHTML (html, options) {
605578
// Remove the open elements from the stack
606579
stack.length = pos;
607580
lastTag = pos && stack[pos - 1].tag;
608-
} else if (tagName.toLowerCase() === 'br') {
581+
} else if (lowerCasedTagName === 'br') {
609582
if (options.start) {
610583
options.start(tagName, [], true, start, end);
611584
}
612-
} else if (tagName.toLowerCase() === 'p') {
585+
} else if (lowerCasedTagName === 'p') {
613586
if (options.start) {
614587
options.start(tagName, [], false, start, end);
615588
}
@@ -719,7 +692,7 @@ function wrapFilter (exp, filter) {
719692
/* */
720693

721694
var defaultTagRE = /\{\{((?:.|\n)+?)\}\}/g;
722-
var regexEscapeRE = /[-.*+?^${}()|[\]/\\]/g;
695+
var regexEscapeRE = /[-.*+?^${}()|[\]\/\\]/g;
723696

724697
var buildRegex = cached(function (delimiters) {
725698
var open = delimiters[0].replace(regexEscapeRE, '\\$&');
@@ -1516,7 +1489,7 @@ function processAttrs (el) {
15161489
name = camelize(name);
15171490
}
15181491
}
1519-
if (isProp || platformMustUseProp(el.tag, name)) {
1492+
if (isProp || platformMustUseProp(el.tag, el.attrsMap.type, name)) {
15201493
addProp(el, name, value);
15211494
} else {
15221495
addAttr(el, name, value);
@@ -1550,15 +1523,6 @@ function processAttrs (el) {
15501523
}
15511524
}
15521525
addAttr(el, name, JSON.stringify(value));
1553-
// #4530 also bind special attributes as props even if they are static
1554-
// so that patches between dynamic/static are consistent
1555-
if (platformMustUseProp(el.tag, name)) {
1556-
if (name === 'value') {
1557-
addProp(el, name, JSON.stringify(value));
1558-
} else {
1559-
addProp(el, name, 'true');
1560-
}
1561-
}
15621526
}
15631527
}
15641528
}
@@ -2135,25 +2099,28 @@ function getNormalizationType (children) {
21352099
var res = 0;
21362100
for (var i = 0; i < children.length; i++) {
21372101
var el = children[i];
2102+
if (el.type !== 1) {
2103+
continue
2104+
}
21382105
if (needsNormalization(el) ||
2139-
(el.if && el.ifConditions.some(function (c) { return needsNormalization(c.block); }))) {
2106+
(el.ifConditions && el.ifConditions.some(function (c) { return needsNormalization(c.block); }))) {
21402107
res = 2;
21412108
break
21422109
}
21432110
if (maybeComponent(el) ||
2144-
(el.if && el.ifConditions.some(function (c) { return maybeComponent(c.block); }))) {
2111+
(el.ifConditions && el.ifConditions.some(function (c) { return maybeComponent(c.block); }))) {
21452112
res = 1;
21462113
}
21472114
}
21482115
return res
21492116
}
21502117

21512118
function needsNormalization (el) {
2152-
return el.for || el.tag === 'template' || el.tag === 'slot'
2119+
return el.for !== undefined || el.tag === 'template' || el.tag === 'slot'
21532120
}
21542121

21552122
function maybeComponent (el) {
2156-
return el.type === 1 && !isPlatformReservedTag$1(el.tag)
2123+
return !isPlatformReservedTag$1(el.tag)
21572124
}
21582125

21592126
function genNode (node) {

packages/weex-template-compiler/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "weex-template-compiler",
3-
"version": "2.1.8-weex.1",
3+
"version": "2.1.9-weex.1",
44
"description": "Weex template compiler for Vue 2.0",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)