From 6473f52c67a87f24c673bed551655bbecc7776ff Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 30 Mar 2021 10:12:02 -0500 Subject: [PATCH 1/3] Convert var to const/let in src files ``` npm install -g jscodeshift git clone https://github.com/cpojer/js-codemod.git jscodeshift -t js-codemod/transforms/no-vars.js ./src ``` --- src/babel.js | 26 +++---- src/coffee-script.js | 10 +-- src/compile-cache.js | 50 ++++++------- src/delegated-listener.js | 2 +- src/history-manager.js | 4 +- src/module-cache.js | 2 +- src/package-manager.js | 2 +- src/package.js | 2 +- src/state-store.js | 10 +-- src/style-manager.js | 2 +- src/text-editor-component.js | 70 +++++++++---------- src/text-editor-registry.js | 2 +- src/text-mate-language-mode.js | 2 +- src/tooltip.js | 124 ++++++++++++++++----------------- src/typescript.js | 16 ++--- src/view-registry.js | 4 +- 16 files changed, 164 insertions(+), 164 deletions(-) diff --git a/src/babel.js b/src/babel.js index 622faaad9..0e52acb10 100644 --- a/src/babel.js +++ b/src/babel.js @@ -1,13 +1,13 @@ 'use strict'; -var crypto = require('crypto'); -var path = require('path'); -var defaultOptions = require('../static/babelrc.json'); +const crypto = require('crypto'); +const path = require('path'); +const defaultOptions = require('../static/babelrc.json'); -var babel = null; -var babelVersionDirectory = null; +let babel = null; +let babelVersionDirectory = null; -var PREFIXES = [ +const PREFIXES = [ '/** @babel */', '"use babel"', "'use babel'", @@ -15,7 +15,7 @@ var PREFIXES = [ '// @flow' ]; -var PREFIX_LENGTH = Math.max.apply( +const PREFIX_LENGTH = Math.max.apply( Math, PREFIXES.map(function(prefix) { return prefix.length; @@ -23,7 +23,7 @@ var PREFIX_LENGTH = Math.max.apply( ); exports.shouldCompile = function(sourceCode) { - var start = sourceCode.substr(0, PREFIX_LENGTH); + const start = sourceCode.substr(0, PREFIX_LENGTH); return PREFIXES.some(function(prefix) { return start.indexOf(prefix) === 0; }); @@ -31,7 +31,7 @@ exports.shouldCompile = function(sourceCode) { exports.getCachePath = function(sourceCode) { if (babelVersionDirectory == null) { - var babelVersion = require('babel-core/package.json').version; + const babelVersion = require('babel-core/package.json').version; babelVersionDirectory = path.join( 'js', 'babel', @@ -51,8 +51,8 @@ exports.getCachePath = function(sourceCode) { exports.compile = function(sourceCode, filePath) { if (!babel) { babel = require('babel-core'); - var Logger = require('babel-core/lib/transformation/file/logger'); - var noop = function() {}; + const Logger = require('babel-core/lib/transformation/file/logger'); + const noop = function() {}; Logger.prototype.debug = noop; Logger.prototype.verbose = noop; } @@ -61,8 +61,8 @@ exports.compile = function(sourceCode, filePath) { filePath = 'file:///' + path.resolve(filePath).replace(/\\/g, '/'); } - var options = { filename: filePath }; - for (var key in defaultOptions) { + const options = { filename: filePath }; + for (const key in defaultOptions) { options[key] = defaultOptions[key]; } return babel.transform(sourceCode, options).code; diff --git a/src/coffee-script.js b/src/coffee-script.js index 389ef5b3b..dcd93ca2e 100644 --- a/src/coffee-script.js +++ b/src/coffee-script.js @@ -1,8 +1,8 @@ 'use strict'; -var crypto = require('crypto'); -var path = require('path'); -var CoffeeScript = null; +const crypto = require('crypto'); +const path = require('path'); +let CoffeeScript = null; exports.shouldCompile = function() { return true; @@ -20,7 +20,7 @@ exports.getCachePath = function(sourceCode) { exports.compile = function(sourceCode, filePath) { if (!CoffeeScript) { - var previousPrepareStackTrace = Error.prepareStackTrace; + const previousPrepareStackTrace = Error.prepareStackTrace; CoffeeScript = require('coffee-script'); // When it loads, coffee-script reassigns Error.prepareStackTrace. We have @@ -33,7 +33,7 @@ exports.compile = function(sourceCode, filePath) { filePath = 'file:///' + path.resolve(filePath).replace(/\\/g, '/'); } - var output = CoffeeScript.compile(sourceCode, { + const output = CoffeeScript.compile(sourceCode, { filename: filePath, sourceFiles: [filePath], inlineMap: true diff --git a/src/compile-cache.js b/src/compile-cache.js index 2e35760ff..5af4898b0 100644 --- a/src/compile-cache.js +++ b/src/compile-cache.js @@ -5,16 +5,16 @@ // Atom's compile-cache when installing or updating packages, using an older // version of node.js -var path = require('path'); -var fs = require('fs-plus'); -var sourceMapSupport = require('@atom/source-map-support'); +const path = require('path'); +const fs = require('fs-plus'); +const sourceMapSupport = require('@atom/source-map-support'); -var PackageTranspilationRegistry = require('./package-transpilation-registry'); -var CSON = null; +const PackageTranspilationRegistry = require('./package-transpilation-registry'); +let CSON = null; -var packageTranspilationRegistry = new PackageTranspilationRegistry(); +const packageTranspilationRegistry = new PackageTranspilationRegistry(); -var COMPILERS = { +const COMPILERS = { '.js': packageTranspilationRegistry.wrapTranspiler(require('./babel')), '.ts': packageTranspilationRegistry.wrapTranspiler(require('./typescript')), '.tsx': packageTranspilationRegistry.wrapTranspiler(require('./typescript')), @@ -43,11 +43,11 @@ exports.removeTranspilerConfigForPath = function(packagePath) { packageTranspilationRegistry.removeTranspilerConfigForPath(packagePath); }; -var cacheStats = {}; -var cacheDirectory = null; +const cacheStats = {}; +let cacheDirectory = null; exports.setAtomHomeDirectory = function(atomHome) { - var cacheDir = path.join(atomHome, 'compile-cache'); + let cacheDir = path.join(atomHome, 'compile-cache'); if ( process.env.USER === 'root' && process.env.SUDO_USER && @@ -68,7 +68,7 @@ exports.getCacheDirectory = function() { exports.addPathToCache = function(filePath, atomHome) { this.setAtomHomeDirectory(atomHome); - var extension = path.extname(filePath); + const extension = path.extname(filePath); if (extension === '.cson') { if (!CSON) { @@ -77,7 +77,7 @@ exports.addPathToCache = function(filePath, atomHome) { } return CSON.readFileSync(filePath); } else { - var compiler = COMPILERS[extension]; + const compiler = COMPILERS[extension]; if (compiler) { return compileFileAtPath(compiler, filePath, extension); } @@ -98,10 +98,10 @@ exports.resetCacheStats = function() { }; function compileFileAtPath(compiler, filePath, extension) { - var sourceCode = fs.readFileSync(filePath, 'utf8'); + const sourceCode = fs.readFileSync(filePath, 'utf8'); if (compiler.shouldCompile(sourceCode, filePath)) { - var cachePath = compiler.getCachePath(sourceCode, filePath); - var compiledCode = readCachedJavaScript(cachePath); + const cachePath = compiler.getCachePath(sourceCode, filePath); + let compiledCode = readCachedJavaScript(cachePath); if (compiledCode != null) { cacheStats[extension].hits++; } else { @@ -115,7 +115,7 @@ function compileFileAtPath(compiler, filePath, extension) { } function readCachedJavaScript(relativeCachePath) { - var cachePath = path.join(cacheDirectory, relativeCachePath); + const cachePath = path.join(cacheDirectory, relativeCachePath); if (fs.isFileSync(cachePath)) { try { return fs.readFileSync(cachePath, 'utf8'); @@ -125,11 +125,11 @@ function readCachedJavaScript(relativeCachePath) { } function writeCachedJavaScript(relativeCachePath, code) { - var cachePath = path.join(cacheDirectory, relativeCachePath); + const cachePath = path.join(cacheDirectory, relativeCachePath); fs.writeFileSync(cachePath, code, 'utf8'); } -var INLINE_SOURCE_MAP_REGEXP = /\/\/[#@]\s*sourceMappingURL=([^'"\n]+)\s*$/gm; +const INLINE_SOURCE_MAP_REGEXP = /\/\/[#@]\s*sourceMappingURL=([^'"\n]+)\s*$/gm; exports.install = function(resourcesPath, nodeRequire) { const snapshotSourceMapConsumer = { @@ -166,7 +166,7 @@ exports.install = function(resourcesPath, nodeRequire) { return null; } - var compiler = COMPILERS[path.extname(filePath)]; + let compiler = COMPILERS[path.extname(filePath)]; if (!compiler) compiler = COMPILERS['.js']; try { @@ -182,7 +182,7 @@ exports.install = function(resourcesPath, nodeRequire) { return null; } - var match, lastMatch; + let match, lastMatch; INLINE_SOURCE_MAP_REGEXP.lastIndex = 0; while ((match = INLINE_SOURCE_MAP_REGEXP.exec(fileData))) { lastMatch = match; @@ -191,8 +191,8 @@ exports.install = function(resourcesPath, nodeRequire) { return null; } - var sourceMappingURL = lastMatch[1]; - var rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1); + const sourceMappingURL = lastMatch[1]; + const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1); try { var sourceMap = JSON.parse(Buffer.from(rawData, 'base64')); @@ -208,7 +208,7 @@ exports.install = function(resourcesPath, nodeRequire) { } }); - var prepareStackTraceWithSourceMapping = Error.prepareStackTrace; + const prepareStackTraceWithSourceMapping = Error.prepareStackTrace; var prepareStackTrace = prepareStackTraceWithSourceMapping; function prepareStackTraceWithRawStackAssignment(error, frames) { @@ -245,13 +245,13 @@ exports.install = function(resourcesPath, nodeRequire) { }; Object.keys(COMPILERS).forEach(function(extension) { - var compiler = COMPILERS[extension]; + const compiler = COMPILERS[extension]; Object.defineProperty(nodeRequire.extensions, extension, { enumerable: true, writable: false, value: function(module, filePath) { - var code = compileFileAtPath(compiler, filePath, extension); + const code = compileFileAtPath(compiler, filePath, extension); return module._compile(code, filePath); } }); diff --git a/src/delegated-listener.js b/src/delegated-listener.js index c977912e8..f2cd33b4d 100644 --- a/src/delegated-listener.js +++ b/src/delegated-listener.js @@ -1,7 +1,7 @@ const EventKit = require('event-kit'); module.exports = function listen(element, eventName, selector, handler) { - var innerHandler = function(event) { + const innerHandler = function(event) { if (selector) { var currentTarget = event.target; while (currentTarget) { diff --git a/src/history-manager.js b/src/history-manager.js index ba9f291cc..fce540654 100644 --- a/src/history-manager.js +++ b/src/history-manager.js @@ -89,7 +89,7 @@ class HistoryManager { } getProject(paths) { - for (var i = 0; i < this.projects.length; i++) { + for (let i = 0; i < this.projects.length; i++) { if (arrayEquivalent(paths, this.projects[i].paths)) { return this.projects[i]; } @@ -121,7 +121,7 @@ class HistoryManager { function arrayEquivalent(a, b) { if (a.length !== b.length) return false; - for (var i = 0; i < a.length; i++) { + for (let i = 0; i < a.length; i++) { if (a[i] !== b[i]) return false; } return true; diff --git a/src/module-cache.js b/src/module-cache.js index 29ff6b2d6..4caa11521 100644 --- a/src/module-cache.js +++ b/src/module-cache.js @@ -73,7 +73,7 @@ function loadDependencies(modulePath, rootPath, rootMetadata, moduleCache) { const childMetadata = JSON.parse(fs.readFileSync(childMetadataPath)); if (childMetadata && childMetadata.version) { - var mainPath; + let mainPath; try { mainPath = require.resolve(childPath); } catch (error) { diff --git a/src/package-manager.js b/src/package-manager.js index 4e1bd5a29..163e3ca9d 100644 --- a/src/package-manager.js +++ b/src/package-manager.js @@ -531,7 +531,7 @@ module.exports = class PackageManager { ) => { for (const packageName of packageNames) { if (!disabledPackageNames.has(packageName)) { - var pack = this.getLoadedPackage(packageName); + const pack = this.getLoadedPackage(packageName); if (pack != null) { action(pack); } diff --git a/src/package.js b/src/package.js index d7c490e3c..0580d1600 100644 --- a/src/package.js +++ b/src/package.js @@ -1173,7 +1173,7 @@ module.exports = class Package { return nativeModulePaths; } - var traversePath = nodeModulesPath => { + const traversePath = nodeModulesPath => { try { for (let modulePath of fs.listSync(nodeModulesPath)) { const modulePathNodeFiles = this.getModulePathNodeFiles(modulePath); diff --git a/src/state-store.js b/src/state-store.js index e8e51afff..bcaa90854 100644 --- a/src/state-store.js +++ b/src/state-store.js @@ -43,7 +43,7 @@ module.exports = class StateStore { this.dbPromise.then(db => { if (db == null) return resolve(); - var request = db + const request = db .transaction(['states'], 'readwrite') .objectStore('states') .put({ value: value, storedAt: new Date().toString() }, key); @@ -59,7 +59,7 @@ module.exports = class StateStore { if (!db) return; return new Promise((resolve, reject) => { - var request = db + const request = db .transaction(['states']) .objectStore('states') .get(key); @@ -83,7 +83,7 @@ module.exports = class StateStore { this.dbPromise.then(db => { if (db == null) return resolve(); - var request = db + const request = db .transaction(['states'], 'readwrite') .objectStore('states') .delete(key); @@ -99,7 +99,7 @@ module.exports = class StateStore { if (!db) return; return new Promise((resolve, reject) => { - var request = db + const request = db .transaction(['states'], 'readwrite') .objectStore('states') .clear(); @@ -115,7 +115,7 @@ module.exports = class StateStore { if (!db) return; return new Promise((resolve, reject) => { - var request = db + const request = db .transaction(['states']) .objectStore('states') .count(); diff --git a/src/style-manager.js b/src/style-manager.js index f29393805..83cb23ff0 100644 --- a/src/style-manager.js +++ b/src/style-manager.js @@ -254,7 +254,7 @@ module.exports = class StyleManager { } buildStylesElement() { - var stylesElement = new StylesElement(); + const stylesElement = new StylesElement(); stylesElement.initialize(this); return stylesElement; } diff --git a/src/text-editor-component.js b/src/text-editor-component.js index 70dba57ce..b1892e869 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -306,7 +306,7 @@ module.exports = class TextEditorComponent { this.remeasureAllBlockDecorations = false; const decorations = this.props.model.getDecorations(); - for (var i = 0; i < decorations.length; i++) { + for (let i = 0; i < decorations.length; i++) { const decoration = decorations[i]; const marker = decoration.getMarker(); if (marker.isValid() && decoration.getProperties().type === 'block') { @@ -2169,7 +2169,7 @@ module.exports = class TextEditorComponent { } autoscrollOnMouseDrag({ clientX, clientY }, verticalOnly = false) { - var { + let { top, bottom, left, @@ -4283,7 +4283,7 @@ class LinesTileComponent { } updateLines(oldProps, newProps) { - var { + const { screenLines, tileStartRow, lineDecorations, @@ -4293,20 +4293,20 @@ class LinesTileComponent { lineComponentsByScreenLineId } = newProps; - var oldScreenLines = oldProps.screenLines; - var newScreenLines = screenLines; - var oldScreenLinesEndIndex = oldScreenLines.length; - var newScreenLinesEndIndex = newScreenLines.length; - var oldScreenLineIndex = 0; - var newScreenLineIndex = 0; - var lineComponentIndex = 0; + const oldScreenLines = oldProps.screenLines; + const newScreenLines = screenLines; + const oldScreenLinesEndIndex = oldScreenLines.length; + const newScreenLinesEndIndex = newScreenLines.length; + let oldScreenLineIndex = 0; + let newScreenLineIndex = 0; + let lineComponentIndex = 0; while ( oldScreenLineIndex < oldScreenLinesEndIndex || newScreenLineIndex < newScreenLinesEndIndex ) { - var oldScreenLine = oldScreenLines[oldScreenLineIndex]; - var newScreenLine = newScreenLines[newScreenLineIndex]; + const oldScreenLine = oldScreenLines[oldScreenLineIndex]; + const newScreenLine = newScreenLines[newScreenLineIndex]; if (oldScreenLineIndex >= oldScreenLinesEndIndex) { var newScreenLineComponent = new LineComponent({ @@ -4329,7 +4329,7 @@ class LinesTileComponent { oldScreenLineIndex++; } else if (oldScreenLine === newScreenLine) { - var lineComponent = this.lineComponents[lineComponentIndex]; + const lineComponent = this.lineComponents[lineComponentIndex]; lineComponent.update({ screenRow: tileStartRow + newScreenLineIndex, lineDecoration: lineDecorations[newScreenLineIndex], @@ -4340,17 +4340,17 @@ class LinesTileComponent { newScreenLineIndex++; lineComponentIndex++; } else { - var oldScreenLineIndexInNewScreenLines = newScreenLines.indexOf( + const oldScreenLineIndexInNewScreenLines = newScreenLines.indexOf( oldScreenLine ); - var newScreenLineIndexInOldScreenLines = oldScreenLines.indexOf( + const newScreenLineIndexInOldScreenLines = oldScreenLines.indexOf( newScreenLine ); if ( newScreenLineIndex < oldScreenLineIndexInNewScreenLines && oldScreenLineIndexInNewScreenLines < newScreenLinesEndIndex ) { - var newScreenLineComponents = []; + const newScreenLineComponents = []; while (newScreenLineIndex < oldScreenLineIndexInNewScreenLines) { // eslint-disable-next-line no-redeclare var newScreenLineComponent = new LineComponent({ @@ -4389,7 +4389,7 @@ class LinesTileComponent { oldScreenLineIndex++; } } else { - var oldScreenLineComponent = this.lineComponents[lineComponentIndex]; + const oldScreenLineComponent = this.lineComponents[lineComponentIndex]; // eslint-disable-next-line no-redeclare var newScreenLineComponent = new LineComponent({ screenLine: newScreenLines[newScreenLineIndex], @@ -4416,13 +4416,13 @@ class LinesTileComponent { } getFirstElementForScreenLine(oldProps, screenLine) { - var blockDecorations = oldProps.blockDecorations + const blockDecorations = oldProps.blockDecorations ? oldProps.blockDecorations.get(screenLine.id) : null; if (blockDecorations) { - var blockDecorationElementsBeforeOldScreenLine = []; + const blockDecorationElementsBeforeOldScreenLine = []; for (let i = 0; i < blockDecorations.length; i++) { - var decoration = blockDecorations[i]; + const decoration = blockDecorations[i]; if (decoration.position !== 'after') { blockDecorationElementsBeforeOldScreenLine.push( TextEditor.viewForItem(decoration.item) @@ -4435,7 +4435,7 @@ class LinesTileComponent { i < blockDecorationElementsBeforeOldScreenLine.length; i++ ) { - var blockDecorationElement = + const blockDecorationElement = blockDecorationElementsBeforeOldScreenLine[i]; if ( !blockDecorationElementsBeforeOldScreenLine.includes( @@ -4451,19 +4451,19 @@ class LinesTileComponent { } updateBlockDecorations(oldProps, newProps) { - var { blockDecorations, lineComponentsByScreenLineId } = newProps; + const { blockDecorations, lineComponentsByScreenLineId } = newProps; if (oldProps.blockDecorations) { oldProps.blockDecorations.forEach((oldDecorations, screenLineId) => { - var newDecorations = newProps.blockDecorations + const newDecorations = newProps.blockDecorations ? newProps.blockDecorations.get(screenLineId) : null; - for (var i = 0; i < oldDecorations.length; i++) { - var oldDecoration = oldDecorations[i]; + for (let i = 0; i < oldDecorations.length; i++) { + const oldDecoration = oldDecorations[i]; if (newDecorations && newDecorations.includes(oldDecoration)) continue; - var element = TextEditor.viewForItem(oldDecoration.item); + const element = TextEditor.viewForItem(oldDecoration.item); if (element.parentElement !== this.element) continue; element.remove(); @@ -5125,11 +5125,11 @@ class NodePool { } getElement(type, className, style) { - var element; - var elementsByDepth = this.elementsByType[type]; + let element; + const elementsByDepth = this.elementsByType[type]; if (elementsByDepth) { while (elementsByDepth.length > 0) { - var elements = elementsByDepth[elementsByDepth.length - 1]; + const elements = elementsByDepth[elementsByDepth.length - 1]; if (elements && elements.length > 0) { element = elements.pop(); if (elements.length === 0) elementsByDepth.pop(); @@ -5150,7 +5150,7 @@ class NodePool { while (element.firstChild) element.firstChild.remove(); return element; } else { - var newElement = document.createElement(type); + const newElement = document.createElement(type); if (className) newElement.className = className; if (style) Object.assign(newElement.style, style); return newElement; @@ -5159,7 +5159,7 @@ class NodePool { getTextNode(text) { if (this.textNodes.length > 0) { - var node = this.textNodes.pop(); + const node = this.textNodes.pop(); node.textContent = text; return node; } else { @@ -5168,24 +5168,24 @@ class NodePool { } release(node, depth = 0) { - var { nodeName } = node; + const { nodeName } = node; if (nodeName === '#text') { this.textNodes.push(node); } else { - var elementsByDepth = this.elementsByType[nodeName]; + let elementsByDepth = this.elementsByType[nodeName]; if (!elementsByDepth) { elementsByDepth = []; this.elementsByType[nodeName] = elementsByDepth; } - var elements = elementsByDepth[depth]; + let elements = elementsByDepth[depth]; if (!elements) { elements = []; elementsByDepth[depth] = elements; } elements.push(node); - for (var i = 0; i < node.childNodes.length; i++) { + for (let i = 0; i < node.childNodes.length; i++) { this.release(node.childNodes[i], depth + 1); } } diff --git a/src/text-editor-registry.js b/src/text-editor-registry.js index b87d08f46..b5264fb5d 100644 --- a/src/text-editor-registry.js +++ b/src/text-editor-registry.js @@ -110,7 +110,7 @@ module.exports = class TextEditorRegistry { // // Returns a {Boolean} indicating whether the editor was successfully removed. remove(editor) { - var removed = this.editors.delete(editor); + const removed = this.editors.delete(editor); editor.registered = false; return removed; } diff --git a/src/text-mate-language-mode.js b/src/text-mate-language-mode.js index 71f2ee701..13d5ed13f 100644 --- a/src/text-mate-language-mode.js +++ b/src/text-mate-language-mode.js @@ -329,7 +329,7 @@ class TextMateLanguageMode { let rowsRemaining = this.chunkSize; while (this.firstInvalidRow() != null && rowsRemaining > 0) { - var endRow, filledRegion; + let endRow, filledRegion; const startRow = this.invalidRows.shift(); const lastRow = this.buffer.getLastRow(); if (startRow > lastRow) continue; diff --git a/src/tooltip.js b/src/tooltip.js index 57d2e35e6..3d59f8036 100644 --- a/src/tooltip.js +++ b/src/tooltip.js @@ -7,9 +7,9 @@ const listen = require('./delegated-listener'); // This tooltip class is derived from Bootstrap 3, but modified to not require // jQuery, which is an expensive dependency we want to eliminate. -var followThroughTimer = null; +let followThroughTimer = null; -var Tooltip = function(element, options, viewRegistry) { +const Tooltip = function(element, options, viewRegistry) { this.options = null; this.enabled = null; this.timeout = null; @@ -66,9 +66,9 @@ Tooltip.prototype.init = function(element, options) { ); } - var triggers = this.options.trigger.split(' '); + const triggers = this.options.trigger.split(' '); - for (var i = triggers.length; i--; ) { + for (let i = triggers.length; i--; ) { var trigger = triggers[i]; if (trigger === 'click') { @@ -91,7 +91,7 @@ Tooltip.prototype.init = function(element, options) { } else if (trigger === 'manual') { this.show(); } else { - var eventIn, eventOut; + let eventIn, eventOut; if (trigger === 'hover') { this.hideOnKeydownOutsideOfTooltip = () => this.hide(); @@ -175,12 +175,12 @@ Tooltip.prototype.getOptions = function(options) { }; Tooltip.prototype.getDelegateOptions = function() { - var options = {}; - var defaults = this.getDefaults(); + const options = {}; + const defaults = this.getDefaults(); if (this._options) { - for (var key of Object.getOwnPropertyNames(this._options)) { - var value = this._options[key]; + for (const key of Object.getOwnPropertyNames(this._options)) { + const value = this._options[key]; if (defaults[key] !== value) options[key] = value; } } @@ -223,7 +223,7 @@ Tooltip.prototype.enter = function(event) { }; Tooltip.prototype.isInStateTrue = function() { - for (var key in this.inState) { + for (const key in this.inState) { if (this.inState[key]) return true; } @@ -272,9 +272,9 @@ Tooltip.prototype.show = function() { ); } - var tip = this.getTooltipElement(); + const tip = this.getTooltipElement(); this.startObservingMutations(); - var tipId = this.getUID('tooltip'); + const tipId = this.getUID('tooltip'); this.setContent(); tip.setAttribute('id', tipId); @@ -282,13 +282,13 @@ Tooltip.prototype.show = function() { if (this.options.animation) tip.classList.add('fade'); - var placement = + let placement = typeof this.options.placement === 'function' ? this.options.placement.call(this, tip, this.element) : this.options.placement; - var autoToken = /\s?auto?\s?/i; - var autoPlace = autoToken.test(placement); + const autoToken = /\s?auto?\s?/i; + const autoPlace = autoToken.test(placement); if (autoPlace) placement = placement.replace(autoToken, '') || 'top'; tip.remove(); @@ -299,13 +299,13 @@ Tooltip.prototype.show = function() { document.body.appendChild(tip); - var pos = this.element.getBoundingClientRect(); - var actualWidth = tip.offsetWidth; - var actualHeight = tip.offsetHeight; + const pos = this.element.getBoundingClientRect(); + const actualWidth = tip.offsetWidth; + const actualHeight = tip.offsetHeight; if (autoPlace) { - var orgPlacement = placement; - var viewportDim = this.viewport.getBoundingClientRect(); + const orgPlacement = placement; + const viewportDim = this.viewport.getBoundingClientRect(); placement = placement === 'bottom' && pos.bottom + actualHeight > viewportDim.bottom @@ -322,7 +322,7 @@ Tooltip.prototype.show = function() { tip.classList.add(placement); } - var calculatedOffset = this.getCalculatedOffset( + const calculatedOffset = this.getCalculatedOffset( placement, pos, actualWidth, @@ -331,7 +331,7 @@ Tooltip.prototype.show = function() { this.applyPlacement(calculatedOffset, placement); - var prevHoverState = this.hoverState; + const prevHoverState = this.hoverState; this.hoverState = null; if (prevHoverState === 'out') this.leave(); @@ -339,15 +339,15 @@ Tooltip.prototype.show = function() { }; Tooltip.prototype.applyPlacement = function(offset, placement) { - var tip = this.getTooltipElement(); + const tip = this.getTooltipElement(); - var width = tip.offsetWidth; - var height = tip.offsetHeight; + const width = tip.offsetWidth; + const height = tip.offsetHeight; // manually read margins because getBoundingClientRect includes difference - var computedStyle = window.getComputedStyle(tip); - var marginTop = parseInt(computedStyle.marginTop, 10); - var marginLeft = parseInt(computedStyle.marginLeft, 10); + const computedStyle = window.getComputedStyle(tip); + const marginTop = parseInt(computedStyle.marginTop, 10); + const marginLeft = parseInt(computedStyle.marginLeft, 10); offset.top += marginTop; offset.left += marginLeft; @@ -358,14 +358,14 @@ Tooltip.prototype.applyPlacement = function(offset, placement) { tip.classList.add('in'); // check to see if placing tip in new offset caused the tip to resize itself - var actualWidth = tip.offsetWidth; - var actualHeight = tip.offsetHeight; + const actualWidth = tip.offsetWidth; + const actualHeight = tip.offsetHeight; if (placement === 'top' && actualHeight !== height) { offset.top = offset.top + height - actualHeight; } - var delta = this.getViewportAdjustedDelta( + const delta = this.getViewportAdjustedDelta( placement, offset, actualWidth, @@ -375,11 +375,11 @@ Tooltip.prototype.applyPlacement = function(offset, placement) { if (delta.left) offset.left += delta.left; else offset.top += delta.top; - var isVertical = /top|bottom/.test(placement); - var arrowDelta = isVertical + const isVertical = /top|bottom/.test(placement); + const arrowDelta = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight; - var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight'; + const arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight'; tip.style.top = offset.top + 'px'; tip.style.left = offset.left + 'px'; @@ -388,8 +388,8 @@ Tooltip.prototype.applyPlacement = function(offset, placement) { }; Tooltip.prototype.replaceArrow = function(delta, dimension, isVertical) { - var arrow = this.getArrowElement(); - var amount = 50 * (1 - delta / dimension) + '%'; + const arrow = this.getArrowElement(); + const amount = 50 * (1 - delta / dimension) + '%'; if (isVertical) { arrow.style.left = amount; @@ -401,17 +401,17 @@ Tooltip.prototype.replaceArrow = function(delta, dimension, isVertical) { }; Tooltip.prototype.setContent = function() { - var tip = this.getTooltipElement(); + const tip = this.getTooltipElement(); if (this.options.class) { tip.classList.add(this.options.class); } - var inner = tip.querySelector('.tooltip-inner'); + const inner = tip.querySelector('.tooltip-inner'); if (this.options.item) { inner.appendChild(this.viewRegistry.getView(this.options.item)); } else { - var title = this.getTitle(); + const title = this.getTitle(); if (this.options.html) { inner.innerHTML = title; } else { @@ -506,16 +506,16 @@ Tooltip.prototype.getViewportAdjustedDelta = function( actualWidth, actualHeight ) { - var delta = { top: 0, left: 0 }; + const delta = { top: 0, left: 0 }; if (!this.viewport) return delta; - var viewportPadding = + const viewportPadding = (this.options.viewport && this.options.viewport.padding) || 0; - var viewportDimensions = this.viewport.getBoundingClientRect(); + const viewportDimensions = this.viewport.getBoundingClientRect(); if (/right|left/.test(placement)) { - var topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll; - var bottomEdgeOffset = + const topEdgeOffset = pos.top - viewportPadding - viewportDimensions.scroll; + const bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight; if (topEdgeOffset < viewportDimensions.top) { // top overflow @@ -529,8 +529,8 @@ Tooltip.prototype.getViewportAdjustedDelta = function( viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset; } } else { - var leftEdgeOffset = pos.left - viewportPadding; - var rightEdgeOffset = pos.left + viewportPadding + actualWidth; + const leftEdgeOffset = pos.left - viewportPadding; + const rightEdgeOffset = pos.left + viewportPadding + actualWidth; if (leftEdgeOffset < viewportDimensions.left) { // left overflow delta.left = viewportDimensions.left - leftEdgeOffset; @@ -545,7 +545,7 @@ Tooltip.prototype.getViewportAdjustedDelta = function( }; Tooltip.prototype.getTitle = function() { - var title = this.element.getAttribute('data-original-title'); + const title = this.element.getAttribute('data-original-title'); if (title) { return title; } else { @@ -617,7 +617,7 @@ Tooltip.prototype.destroy = function() { }; Tooltip.prototype.getDelegateComponent = function(element) { - var component = tooltipComponentsByElement.get(element); + let component = tooltipComponentsByElement.get(element); if (!component) { component = new Tooltip( element, @@ -630,26 +630,26 @@ Tooltip.prototype.getDelegateComponent = function(element) { }; Tooltip.prototype.recalculatePosition = function() { - var tip = this.getTooltipElement(); + const tip = this.getTooltipElement(); - var placement = + let placement = typeof this.options.placement === 'function' ? this.options.placement.call(this, tip, this.element) : this.options.placement; - var autoToken = /\s?auto?\s?/i; - var autoPlace = autoToken.test(placement); + const autoToken = /\s?auto?\s?/i; + const autoPlace = autoToken.test(placement); if (autoPlace) placement = placement.replace(autoToken, '') || 'top'; tip.classList.add(placement); - var pos = this.element.getBoundingClientRect(); - var actualWidth = tip.offsetWidth; - var actualHeight = tip.offsetHeight; + const pos = this.element.getBoundingClientRect(); + const actualWidth = tip.offsetWidth; + const actualHeight = tip.offsetHeight; if (autoPlace) { - var orgPlacement = placement; - var viewportDim = this.viewport.getBoundingClientRect(); + const orgPlacement = placement; + const viewportDim = this.viewport.getBoundingClientRect(); placement = placement === 'bottom' && pos.bottom + actualHeight > viewportDim.bottom @@ -666,7 +666,7 @@ Tooltip.prototype.recalculatePosition = function() { tip.classList.add(placement); } - var calculatedOffset = this.getCalculatedOffset( + const calculatedOffset = this.getCalculatedOffset( placement, pos, actualWidth, @@ -676,11 +676,11 @@ Tooltip.prototype.recalculatePosition = function() { }; function extend() { - var args = Array.prototype.slice.apply(arguments); - var target = args.shift(); - var source = args.shift(); + const args = Array.prototype.slice.apply(arguments); + const target = args.shift(); + let source = args.shift(); while (source) { - for (var key of Object.getOwnPropertyNames(source)) { + for (const key of Object.getOwnPropertyNames(source)) { target[key] = source[key]; } source = args.shift(); diff --git a/src/typescript.js b/src/typescript.js index f10410ea1..2995224b1 100644 --- a/src/typescript.js +++ b/src/typescript.js @@ -1,17 +1,17 @@ 'use strict'; -var _ = require('underscore-plus'); -var crypto = require('crypto'); -var path = require('path'); +const _ = require('underscore-plus'); +const crypto = require('crypto'); +const path = require('path'); -var defaultOptions = { +const defaultOptions = { target: 1, module: 'commonjs', sourceMap: true }; -var TypeScriptSimple = null; -var typescriptVersionDir = null; +let TypeScriptSimple = null; +let typescriptVersionDir = null; exports.shouldCompile = function() { return true; @@ -19,7 +19,7 @@ exports.shouldCompile = function() { exports.getCachePath = function(sourceCode) { if (typescriptVersionDir == null) { - var version = require('typescript-simple/package.json').version; + const version = require('typescript-simple/package.json').version; typescriptVersionDir = path.join( 'ts', createVersionAndOptionsDigest(version, defaultOptions) @@ -44,7 +44,7 @@ exports.compile = function(sourceCode, filePath) { filePath = 'file:///' + path.resolve(filePath).replace(/\\/g, '/'); } - var options = _.defaults({ filename: filePath }, defaultOptions); + const options = _.defaults({ filename: filePath }, defaultOptions); return new TypeScriptSimple(options, false).compile(sourceCode, filePath); }; diff --git a/src/view-registry.js b/src/view-registry.js index 5f70d7d37..698dbc325 100644 --- a/src/view-registry.js +++ b/src/view-registry.js @@ -259,13 +259,13 @@ module.exports = class ViewRegistry { this.nextUpdatePromise = null; this.resolveNextUpdatePromise = null; - var writer = this.documentWriters.shift(); + let writer = this.documentWriters.shift(); while (writer) { writer(); writer = this.documentWriters.shift(); } - var reader = this.documentReaders.shift(); + let reader = this.documentReaders.shift(); this.documentReadInProgress = true; while (reader) { reader(); From 3a8200e60afb4494abd11e0cd424550358242a29 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 30 Mar 2021 10:27:27 -0500 Subject: [PATCH 2/3] script/lint fix --- src/text-editor-component.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/text-editor-component.js b/src/text-editor-component.js index b1892e869..a9fff7ff8 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -4389,7 +4389,9 @@ class LinesTileComponent { oldScreenLineIndex++; } } else { - const oldScreenLineComponent = this.lineComponents[lineComponentIndex]; + const oldScreenLineComponent = this.lineComponents[ + lineComponentIndex + ]; // eslint-disable-next-line no-redeclare var newScreenLineComponent = new LineComponent({ screenLine: newScreenLines[newScreenLineIndex], From 7c7890cac0f90dd5cfee664b97b5fbf052a6101d Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 30 Mar 2021 12:15:24 -0500 Subject: [PATCH 3/3] Fix old comment --- src/compile-cache.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/compile-cache.js b/src/compile-cache.js index 5af4898b0..cf7e6711c 100644 --- a/src/compile-cache.js +++ b/src/compile-cache.js @@ -1,9 +1,6 @@ 'use strict'; -// For now, we're not using babel or ES6 features like `let` and `const` in -// this file, because `apm` requires this file directly in order to pre-warm -// Atom's compile-cache when installing or updating packages, using an older -// version of node.js +// Atom's compile-cache when installing or updating packages, called by apm's Node-js const path = require('path'); const fs = require('fs-plus');