Skip to content
This repository has been archived by the owner on Apr 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #370 from tildeio/remove-ie8-workarounds
Browse files Browse the repository at this point in the history
Remove IE8 workarounds
  • Loading branch information
mixonic committed Jun 19, 2015
2 parents 6ac84bc + 4936ae1 commit 0522699
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 151 deletions.
29 changes: 0 additions & 29 deletions packages/htmlbars-compiler/tests/html-compiler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@ var xhtmlNamespace = "http://www.w3.org/1999/xhtml",

var hooks, helpers, partials, env;

// IE8 doesn't correctly handle these html strings
var innerHTMLSupportsCustomTags = (function() {
var div = document.createElement('div');
div.innerHTML = '<x-bar></x-bar>';
return normalizeInnerHTML(div.innerHTML) === '<x-bar></x-bar>';
})();

// IE8 doesn't handle newlines in innerHTML correctly
var innerHTMLHandlesNewlines = (function() {
var div = document.createElement('div');
div.innerHTML = 'foo\n\nbar';
return div.innerHTML.length === 8;
})();

function registerHelper(name, callback) {
helpers[name] = callback;
}
Expand Down Expand Up @@ -215,14 +201,10 @@ test("The compiler can handle backslashes", function() {
compilesTo('<div>This is a backslash: \\</div>');
});

if (innerHTMLHandlesNewlines) {

test("The compiler can handle newlines", function() {
compilesTo("<div>common\n\nbro</div>");
});

}

test("The compiler can handle comments", function() {
compilesTo("<div>{{! Better not break! }}content</div>", '<div>content</div>', {});
});
Expand Down Expand Up @@ -704,8 +686,6 @@ test('Components - Called as helpers', function () {
compilesTo('a<x-append text="d{{bar}}">b{{baz}}</x-append>f','abcf', object);
});

if (innerHTMLSupportsCustomTags) {

test('Components - Unknown helpers fall back to elements', function () {
var object = { size: 'med', foo: 'b' };
compilesTo('<x-bar class="btn-{{size}}">a{{foo}}c</x-bar>','<x-bar class="btn-med">abc</x-bar>', object);
Expand All @@ -725,8 +705,6 @@ test('Components - Text-only dashed attributes work', function () {
compilesTo('<x-bar aria-label="foo" id="test">{{foo}}</x-bar>','<x-bar aria-label="foo" id="test">qux</x-bar>', object);
});

}

test('Repaired text nodes are ensured in the right place', function () {
var object = { a: "A", b: "B", c: "C", d: "D" };
compilesTo('{{a}} {{b}}', 'A B', object);
Expand Down Expand Up @@ -907,11 +885,6 @@ test("A helpful error message is provided for mismatched start/end tags", functi
}, /Closing tag `div` \(on line 5\) did not match last open tag `p` \(on line 2\)\./);
});

// These skipped tests don't actually have anything to do with innerHTML,
// but are related to IE8 doing Bad Things with newlines. This should
// likely have its own feature detect instead of using this one.
if (innerHTMLHandlesNewlines) {

test("error line numbers include comment lines", function() {
QUnit.throws(function() {
compile("<div>\n<p>\n{{! some comment}}\n\n</div>");
Expand Down Expand Up @@ -942,8 +915,6 @@ test("error line numbers include multiple mustache lines", function() {
}, /Closing tag `div` \(on line 3\) did not match last open tag `p` \(on line 2\)\./);
});

}

if (document.createElement('div').namespaceURI) {

QUnit.module("HTML-based compiler (output, svg)", {
Expand Down
6 changes: 3 additions & 3 deletions packages/htmlbars-runtime/lib/expression-visitor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { merge, createObject } from "../htmlbars-util/object-utils";
import { merge } from "../htmlbars-util/object-utils";
import { validateChildMorphs, linkParams } from "../htmlbars-util/morph-utils";

/**
Expand Down Expand Up @@ -104,7 +104,7 @@ var base = {
}
};

export var AlwaysDirtyVisitor = merge(createObject(base), {
export var AlwaysDirtyVisitor = merge(Object.create(base), {
// [ 'block', path, params, hash, templateId, inverseId ]
block: function(node, morph, env, scope, template, visitor) {
var path = node[1], params = node[2], hash = node[3], templateId = node[4], inverseId = node[5];
Expand Down Expand Up @@ -190,7 +190,7 @@ export var AlwaysDirtyVisitor = merge(createObject(base), {
}
});

export default merge(createObject(base), {
export default merge(Object.create(base), {
// [ 'block', path, params, hash, templateId, inverseId ]
block: function(node, morph, env, scope, template, visitor) {
dirtyCheck(env, morph, visitor, function(visitor) {
Expand Down
6 changes: 3 additions & 3 deletions packages/htmlbars-runtime/lib/hooks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import render from "./render";
import MorphList from "../morph-range/morph-list";
import { createChildMorph } from "./render";
import { createObject, keyLength, shallowCopy } from "../htmlbars-util/object-utils";
import { keyLength, shallowCopy } from "../htmlbars-util/object-utils";
import { validateChildMorphs } from "../htmlbars-util/morph-utils";
import { RenderState, clearMorph, clearMorphList, renderAndCleanup } from "../htmlbars-util/template-utils";
import { linkParams } from "../htmlbars-util/morph-utils";
Expand Down Expand Up @@ -430,8 +430,8 @@ export function bindShadowScope(env /*, parentScope, shadowScope */) {
}

export function createChildScope(parent) {
var scope = createObject(parent);
scope.locals = createObject(parent.locals);
var scope = Object.create(parent);
scope.locals = Object.create(parent.locals);
return scope;
}

Expand Down
3 changes: 1 addition & 2 deletions packages/htmlbars-runtime/lib/morph.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import MorphBase from "../morph-range";
import { createObject } from "../htmlbars-util/object-utils";

var guid = 1;

Expand Down Expand Up @@ -42,7 +41,7 @@ HTMLBarsMorph.attach = function (domHelper, contextualElement, firstNode, lastNo
return morph;
};

var prototype = HTMLBarsMorph.prototype = createObject(MorphBase.prototype);
var prototype = HTMLBarsMorph.prototype = Object.create(MorphBase.prototype);
prototype.constructor = HTMLBarsMorph;
prototype.super$constructor = MorphBase;

Expand Down
16 changes: 1 addition & 15 deletions packages/htmlbars-syntax/lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ export function preprocess(html, options) {

export default preprocess;

var splitLines;
// IE8 throws away blank pieces when splitting strings with a regex
// So we split using a string instead as appropriate
if ("foo\n\nbar".split(/\n/).length === 2) {
splitLines = function(str) {
var clean = str.replace(/\r\n?/g, '\n');
return clean.split('\n');
};
} else {
splitLines = function(str) {
return str.split(/(?:\r\n?|\n)/g);
};
}

const entityParser = new EntityParser(fullCharRefs);

export function Parser(source, options) {
Expand All @@ -50,7 +36,7 @@ export function Parser(source, options) {
this.currentAttribute = null;

if (typeof source === 'string') {
this.source = splitLines(source);
this.source = source.split(/(?:\r\n?|\n)/g);
}
}

Expand Down
55 changes: 1 addition & 54 deletions packages/htmlbars-test-helpers/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,14 @@ export function equalHTML(node, html) {
equalInnerHTML(div, html);
}

// IE8 removes comments and does other unspeakable things with innerHTML
var ie8GenerateTokensNeeded = (function() {
var div = document.createElement("div");
div.innerHTML = "<!-- foobar -->";
return div.innerHTML === "";
})();

function generateTokens(fragmentOrHtml) {
var div = document.createElement("div");
if (typeof fragmentOrHtml === 'string') {
div.innerHTML = fragmentOrHtml;
} else {
div.appendChild(fragmentOrHtml.cloneNode(true));
}
if (ie8GenerateTokensNeeded) {
// IE8 drops comments and does other unspeakable things on `innerHTML`.
// So in that case we do it to both the expected and actual so that they match.
var div2 = document.createElement("div");
div2.innerHTML = div.innerHTML;
div.innerHTML = div2.innerHTML;
}

return { tokens: tokenize(div.innerHTML), html: div.innerHTML };
}

Expand Down Expand Up @@ -74,11 +61,6 @@ export function equalTokens(fragment, html, message) {
deepEqual(fragTokens.tokens, htmlTokens.tokens, msg);
}

// detect weird IE8 html strings
var ie8InnerHTMLTestElement = document.createElement('div');
ie8InnerHTMLTestElement.setAttribute('id', 'womp');
var ie8InnerHTML = (ie8InnerHTMLTestElement.outerHTML.indexOf('id=womp') > -1);

// detect side-effects of cloning svg elements in IE9-11
var ieSVGInnerHTML = (function () {
if (!document.createElementNS) {
Expand All @@ -92,29 +74,6 @@ var ieSVGInnerHTML = (function () {
})();

export function normalizeInnerHTML(actualHTML) {
if (ie8InnerHTML) {
// drop newlines in IE8
actualHTML = actualHTML.replace(/\r\n/gm, '');
// downcase ALLCAPS tags in IE8
actualHTML = actualHTML.replace(/<\/?[A-Z\-]+/gi, function(tag){
return tag.toLowerCase();
});
// quote ids in IE8
actualHTML = actualHTML.replace(/id=([^ >]+)/gi, function(match, id){
return 'id="'+id+'"';
});
// IE8 adds ':' to some tags
// <keygen> becomes <:keygen>
actualHTML = actualHTML.replace(/<(\/?):([^ >]+)/gi, function(match, slash, tag){
return '<'+slash+tag;
});

// Normalize the style attribute
actualHTML = actualHTML.replace(/style="(.+?)"/gi, function(match, val){
return 'style="'+val.toLowerCase()+';"';
});

}
if (ieSVGInnerHTML) {
// Replace `<svg xmlns="http://www.w3.org/2000/svg" height="50%" />` with `<svg height="50%"></svg>`, etc.
// drop namespace attribute
Expand Down Expand Up @@ -146,15 +105,3 @@ export function getTextContent(el) {
return el[textProperty];
}
}

// IE8 does not have Object.create, so use a polyfill if needed.
// Polyfill based on Mozilla's (MDN)
export function createObject(obj) {
if (typeof Object.create === 'function') {
return Object.create(obj);
} else {
var Temp = function() {};
Temp.prototype = obj;
return new Temp();
}
}
32 changes: 0 additions & 32 deletions packages/htmlbars-util/lib/object-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,10 @@ export function merge(options, defaults) {
return options;
}

// IE8 does not have Object.create, so use a polyfill if needed.
// Polyfill based on Mozilla's (MDN)
export function createObject(obj) {
if (typeof Object.create === 'function') {
return Object.create(obj);
} else {
var Temp = function() {};
Temp.prototype = obj;
return new Temp();
}
}

export function objectKeys(obj) {
if (typeof Object.keys === 'function') {
return Object.keys(obj);
} else {
return legacyKeys(obj);
}
}

export function shallowCopy(obj) {
return merge({}, obj);
}

function legacyKeys(obj) {
var keys = [];

for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
keys.push(prop);
}
}

return keys;
}

export function keySet(obj) {
var set = {};

Expand Down
8 changes: 1 addition & 7 deletions packages/morph-attr/tests/attr-morph-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,7 @@ test("can update style attribute", function(){
var element = domHelper.createElement('div');
var morph = domHelper.createAttrMorph(element, 'style');
morph.setContent('color: red;');
// IE8 capitalizes css property names and removes trailing semicolons
var value = element.getAttribute('style');
value = value.toLowerCase();
if (value.lastIndexOf(';') !== value.length - 1) {
value += ';';
}
equal(value, 'color: red;', 'style attr is set');
equal(element.getAttribute('style'), 'color: red;', 'style attr is set');
morph.setContent(null);
equal(element.getAttribute('style'), undefined, 'style attr is removed');
});
Expand Down
7 changes: 1 addition & 6 deletions testem-sauce.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
"SL_IE_9": {
"command": "ember sauce:launch -b 'internet explorer' -v 9 --no-ct -u <url>",
"protocol": "tap"
},
"SL_IE_8": {
"command": "ember sauce:launch -b 'internet explorer' -v 8 --no-ct -u <url>",
"protocol": "tap"
}
}
,
Expand All @@ -62,7 +58,6 @@
"SL_Safari_Last",
"SL_IE_11",
"SL_IE_10",
"SL_IE_9",
"SL_IE_8"
"SL_IE_9"
]
}

0 comments on commit 0522699

Please sign in to comment.