소스 검색

replaced let with const

Gildas 7 년 전
부모
커밋
dee66f4f17

+ 1 - 2
extension/core/bg/storage.js

@@ -22,8 +22,7 @@
 
 singlefile.storage = (() => {
 
-	let persistentData;
-	let temporaryData;
+	let persistentData, temporaryData;
 	browser.tabs.onRemoved.addListener(async tabId => {
 		const tabsData = await singlefile.storage.get();
 		delete tabsData[tabId];

+ 1 - 1
extension/ui/bg/ui-button.js

@@ -196,7 +196,7 @@ singlefile.ui.button = (() => {
 	}
 
 	async function refreshAsync(tabId, tabsData, tabData, force) {
-		for (let property of BUTTON_PROPERTIES) {
+		for (const property of BUTTON_PROPERTIES) {
 			await refreshProperty(tabId, tabsData, property.name, property.browserActionMethod, tabData, force);
 		}
 	}

+ 3 - 6
lib/single-file/css-declarations-parser.js

@@ -392,8 +392,7 @@ this.parseCss = this.parseCss || (() => {
 	}
 
 	function consumeAName(consume, next, eof, reconsume) {
-		let result = "";
-		let code;
+		let result = "", code;
 		while (code = consume()) { // eslint-disable-line no-cond-assign
 			if (namechar(code)) {
 				result += String.fromCodePoint(code);
@@ -407,8 +406,7 @@ this.parseCss = this.parseCss || (() => {
 	}
 
 	function consumeANumber(consume, next) {
-		let repr = [];
-		let type = "integer";
+		let repr = [], type = "integer";
 		let code;
 		if (next() == 0x2b || next() == 0x2d) {
 			code = consume();
@@ -484,8 +482,7 @@ this.parseCss = this.parseCss || (() => {
 		let code;
 
 		// Line number information.
-		let line = 0;
-		let column = 0;
+		let line = 0, column = 0;
 
 		// The only use of lastLineLength is in reconsume().
 		let lastLineLength = 0;

+ 3 - 9
lib/single-file/css-media-query-parser.js

@@ -40,11 +40,7 @@ this.mediaQueryParser = (() => {
 			character: null,
 		}];
 		const result = [];
-		let lastModeIndex = 0;
-		let mediaFeature = "";
-		let colon = null;
-		let mediaFeatureValue = null;
-		let indexLocal = index;
+		let lastModeIndex = 0, mediaFeature = "", colon = null, mediaFeatureValue = null, indexLocal = index;
 
 		let stringNormalized = string;
 		// Strip trailing parens (if any), and correct the starting index
@@ -149,8 +145,7 @@ this.mediaQueryParser = (() => {
 		let localLevel = 0;
 		// Has any keyword, media type, media feature expression or interpolation
 		// ('element' hereafter) started
-		let insideSomeValue = false;
-		let node;
+		let insideSomeValue = false, node;
 
 		function resetNode() {
 			return {
@@ -306,8 +301,7 @@ this.mediaQueryParser = (() => {
 
 	function parseMediaList(string) {
 		const result = [];
-		let interimIndex = 0;
-		let levelLocal = 0;
+		let interimIndex = 0, levelLocal = 0;
 
 		// Check for a `url(...)` part (if it is contents of an @import rule)
 		const doesHaveUrl = /^(\s*)url\s*\(/.exec(string);

+ 2 - 1
lib/single-file/css-minifier.js

@@ -666,7 +666,8 @@ this.uglifycss = this.uglifycss || (() => {
 		// this makes it more likely that it'll get further compressed in the next step.
 		pattern = REGEXP_REPLACE_RGB;
 		content = content.replace(pattern, (_, f1) => {
-			let rgbcolors = f1.split(","), hexcolor = "#";
+			const rgbcolors = f1.split(",");
+			let hexcolor = "#";
 			for (let i = 0; i < rgbcolors.length; i += 1) {
 				let val = parseInt(rgbcolors[i], 10);
 				if (val < 16) {

+ 3 - 3
lib/single-file/css-rules-matcher.js

@@ -44,7 +44,7 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 			const matchedElementsCache = new Map();
 			doc.querySelectorAll("style").forEach((styleElement, sheetIndex) => {
 				if (styleElement.sheet) {
-					let cssRules = styleElement.sheet.cssRules;
+					const cssRules = styleElement.sheet.cssRules;
 					if (styleElement.media && styleElement.media != MEDIA_ALL) {
 						const mediaInfo = createMediaInfo(styleElement.media);
 						this.mediaAllInfo.medias.set("style-" + sheetIndex + "-" + styleElement.media, mediaInfo);
@@ -194,7 +194,7 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 			} else {
 				const styleInfo = elementStyleInfo.selectorInfo.styleInfo;
 				const cssStyle = styleInfo.cssStyle;
-				let matchedStyleInfo = mediaAllInfo.matchedStyles.get(cssStyle);
+				const matchedStyleInfo = mediaAllInfo.matchedStyles.get(cssStyle);
 				if (!matchedStyleInfo) {
 					mediaAllInfo.matchedStyles.set(cssStyle, styleInfo);
 				}
@@ -224,7 +224,7 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 				stylesInfo.forEach(styleInfo => {
 					const important = cssStyle.getPropertyPriority(styleInfo.name);
 					const styleValue = cssStyle.getPropertyValue(styleInfo.name) + (important && "!" + important);
-					let elementStyleInfo = elementStylesInfo.get(styleInfo.name);
+					const elementStyleInfo = elementStylesInfo.get(styleInfo.name);
 					if (!elementStyleInfo || (important && !elementStyleInfo.important)) {
 						elementStylesInfo.set(styleInfo.name, { selectorInfo, styleValue, important });
 					}

+ 2 - 3
lib/single-file/css-rules-minifier.js

@@ -48,7 +48,7 @@ this.cssMinifier = this.cssMinifier || (() => {
 				log("  -- STARTED processStyleAttribute");
 			}
 			doc.querySelectorAll("[style]").forEach(element => {
-				let textContent = processStyleAttribute(element.style, mediaAllInfo);
+				const textContent = processStyleAttribute(element.style, mediaAllInfo);
 				if (textContent) {
 					element.setAttribute("style", textContent);
 				} else {
@@ -63,8 +63,7 @@ this.cssMinifier = this.cssMinifier || (() => {
 	};
 
 	function processRules(doc, cssRules, sheetIndex, mediaInfo) {
-		let sheetContent = "", mediaRuleIndex = 0;
-		let startTime;
+		let sheetContent = "", mediaRuleIndex = 0, startTime;
 		if (DEBUG && cssRules.length > 1) {
 			startTime = Date.now();
 			log("  -- STARTED processRules", "rules.length =", cssRules.length);

+ 1 - 3
lib/single-file/css-selector-parser.js

@@ -157,9 +157,7 @@ this.cssWhat = this.cssWhat || (() => {
 	}
 
 	function parseSelector(subselects, selector, options) {
-		let tokens = [];
-		let sawWS = false;
-		let data, firstChar, name, quot;
+		let tokens = [], sawWS = false, data, firstChar, name, quot;
 		stripWhitespace(0);
 		while (selector != "") {
 			firstChar = selector.charAt(0);

+ 3 - 4
lib/single-file/doc-helper.js

@@ -118,8 +118,8 @@ this.docHelper = this.docHelper || (() => {
 	}
 
 	function hiddenElement(element, ignoredTags) {
-		let cacheElementsHidden = new Map();
-		let hidden = testHiddenElement(element, ignoredTags, cacheElementsHidden);
+		const cacheElementsHidden = new Map();
+		const hidden = testHiddenElement(element, ignoredTags, cacheElementsHidden);
 		if (!hidden) {
 			let parentElement = element.parentElement;
 			if (parentElement) {
@@ -307,8 +307,7 @@ this.docHelper = this.docHelper || (() => {
 					imageElement = element;
 				}
 				if (imageElement) {
-					let naturalWidth = imageElement.naturalWidth;
-					let naturalHeight = imageElement.naturalHeight;
+					let naturalWidth = imageElement.naturalWidth, naturalHeight = imageElement.naturalHeight;
 					if (naturalWidth <= 1 && naturalHeight <= 1) {
 						const imgElement = doc.createElement("img");
 						imgElement.src = imageElement.src;

+ 2 - 1
lib/single-file/frame-tree.js

@@ -35,7 +35,8 @@ this.frameTree = this.frameTree || (() => {
 	const WINDOW_ID_SEPARATOR = ".";
 	const TOP_WINDOW = window == top;
 
-	let sessions = new Map(), windowId;
+	const sessions = new Map();
+	let windowId;
 
 	if (TOP_WINDOW) {
 		windowId = TOP_WINDOW_ID;

+ 2 - 2
lib/single-file/html-minifier.js

@@ -175,7 +175,7 @@ this.htmlmini = this.htmlmini || (() => {
 	function mergeElements(node, tagName, acceptMerge) {
 		if (node.nodeType == Node.ELEMENT_NODE && node.tagName.toLowerCase() == tagName.toLowerCase()) {
 			let previousSibling = node.previousSibling;
-			let previousSiblings = [];
+			const previousSiblings = [];
 			while (previousSibling && previousSibling.nodeType == Node.TEXT_NODE && !previousSibling.textContent.trim()) {
 				previousSiblings.push(previousSibling);
 				previousSibling = previousSibling.previousSibling;
@@ -192,7 +192,7 @@ this.htmlmini = this.htmlmini || (() => {
 		if (node.nodeType == Node.TEXT_NODE) {
 			let element = node.parentElement;
 			const spacePreserved = element.getAttribute(options.preservedSpaceAttributeName) == "";
-			let textContent = node.textContent;
+			const textContent = node.textContent;
 			let noWhitespace = !spacePreserved && noWhitespaceCollapse(element);
 			while (noWhitespace) {
 				element = element.parentElement;

+ 1 - 1
lib/single-file/html-serializer.js

@@ -83,7 +83,7 @@ this.serializer = this.serializer || (() => {
 	}
 
 	function serializeTextNode(textNode) {
-		let parentNode = textNode.parentNode;
+		const parentNode = textNode.parentNode;
 		let parentTagName;
 		if (parentNode && parentNode.nodeType == Node.ELEMENT_NODE) {
 			parentTagName = parentNode.tagName.toLowerCase();

+ 2 - 3
lib/single-file/single-file-browser.js

@@ -54,12 +54,11 @@ this.SingleFile = this.SingleFile || (() => {
 
 	class Download {
 		static async getContent(resourceURL, options) {
-			let startTime;
+			let resourceContent, startTime;
 			if (DEBUG) {
 				startTime = Date.now();
 				log("  // STARTED download url =", resourceURL, "asDataURI =", options.asDataURI);
 			}
-			let resourceContent;
 			if (!fetchResource) {
 				fetchResource = typeof superFetch == "undefined" ? fetch : superFetch.fetch;
 			}
@@ -185,7 +184,7 @@ this.SingleFile = this.SingleFile || (() => {
 		static getOnEventAttributeNames(doc) {
 			const element = doc.createElement("div");
 			const attributeNames = [];
-			for (let propertyName in element) {
+			for (const propertyName in element) {
 				if (propertyName.startsWith("on")) {
 					attributeNames.push(propertyName);
 				}

+ 1 - 2
lib/single-file/single-file-core.js

@@ -1236,8 +1236,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 		}
 
 		static getLastSegment(url) {
-			let lastSegmentMatch = url.pathname.match(/\/([^/]+)$/);
-			let lastSegment = lastSegmentMatch && lastSegmentMatch[0];
+			let lastSegmentMatch = url.pathname.match(/\/([^/]+)$/), lastSegment = lastSegmentMatch && lastSegmentMatch[0];
 			if (!lastSegment) {
 				lastSegmentMatch = url.href.match(/([^/]+)\/?$/);
 				lastSegment = lastSegmentMatch && lastSegmentMatch[0];