浏览代码

don't use Array#join

Gildas 7 年之前
父节点
当前提交
2d56bd8a1e
共有 1 个文件被更改,包括 8 次插入14 次删除
  1. 8 14
      lib/single-file/css-what.js

+ 8 - 14
lib/single-file/css-what.js

@@ -82,10 +82,14 @@ this.cssWhat = this.cssWhat || (() => {
 			universal: "*"
 		};
 		function stringify(token) {
-			return token.map(stringifySubselector).join(", ");
+			let value = "";
+			token.forEach(token => value += stringifySubselector(token) + ",");
+			return value.substring(0, value.length - 1);
 		}
 		function stringifySubselector(token) {
-			return token.map(stringifyToken).join("");
+			let value = "";
+			token.forEach(token => value += stringifyToken(token));
+			return value;
 		}
 		function stringifyToken(token) {
 			if (token.type in simpleSelectors) return simpleSelectors[token.type];
@@ -120,20 +124,12 @@ this.cssWhat = this.cssWhat || (() => {
 
 	// cssEscape taken from https://mathiasbynens.be/notes/css-escapes
 	function cssEscape(string, escapeNonASCII) {
-		// Based on `ucs2decode` from https://mths.be/punycode
 		const firstChar = string.charAt(0);
-		let output = "";
-		let counter = 0;
 		const length = string.length;
-		let value;
-		let character;
-		let charCode;
-		let surrogatePairCount = 0;
-		let extraCharCode; // low surrogate
+		let value, character, charCode, output = "", counter = 0, surrogatePairCount = 0, extraCharCode; // low surrogate
 		while (counter < length) {
 			character = string.charAt(counter++);
 			charCode = character.charCodeAt();
-			// if it’s a non-ASCII character and those need to be escaped
 			if (escapeNonASCII && (charCode < 0x20 || charCode > 0x7E)) {
 				if ((charCode & 0xF800) == 0xD800) {
 					surrogatePairCount++;
@@ -145,8 +141,6 @@ this.cssWhat = this.cssWhat || (() => {
 				}
 				value = "\\" + charCode.toString(16).toUpperCase() + " ";
 			} else {
-				// `\r` is already tokenized away at this point by the HTML parser.
-				// `:` can be escaped as `\:`, but that fails in IE < 8.
 				if (/[\t\n\v\f:]/.test(character)) {
 					value = "\\" + charCode.toString(16).toUpperCase() + " ";
 				} else if (/[ !"#$%&'()*+,./;<=>?@[\\\]^`{|}~]/.test(character)) {
@@ -157,7 +151,7 @@ this.cssWhat = this.cssWhat || (() => {
 			}
 			output += value;
 		}
-		if (/^_/.test(output)) { // Prevent IE6 from ignoring the rule altogether.
+		if (/^_/.test(output)) {
 			output = "\\_" + output.slice(1);
 		}
 		if (/^-[\d]/.test(output)) {