mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-11 19:17:09 +03:00
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 ```
This commit is contained in:
parent
2beb93b0d7
commit
6473f52c67
26
src/babel.js
26
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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -254,7 +254,7 @@ module.exports = class StyleManager {
|
||||
}
|
||||
|
||||
buildStylesElement() {
|
||||
var stylesElement = new StylesElement();
|
||||
const stylesElement = new StylesElement();
|
||||
stylesElement.initialize(this);
|
||||
return stylesElement;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
124
src/tooltip.js
124
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();
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user