mirror of https://github.com/zulip/zulip.git
typescript: Fix violations of new typescript rules.
This commit is contained in:
parent
02cb85a8a9
commit
90478fc4b2
|
@ -4,9 +4,9 @@ import * as _ from 'underscore';
|
||||||
* Implementation detail of the Dict class. `key` is `k` converted to a string,
|
* Implementation detail of the Dict class. `key` is `k` converted to a string,
|
||||||
* in lowercase if the `fold_case` option is enabled.
|
* in lowercase if the `fold_case` option is enabled.
|
||||||
*/
|
*/
|
||||||
type KeyValue<K, V> = { k: K, v: V }
|
type KeyValue<K, V> = { k: K; v: V }
|
||||||
type Items<K, V> = {
|
type Items<K, V> = {
|
||||||
[key: string]: KeyValue<K, V>
|
[key: string]: KeyValue<K, V>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,16 +64,6 @@ export class Dict<K, V> {
|
||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle case-folding of keys and the empty string.
|
|
||||||
private _munge(key: K): string | undefined {
|
|
||||||
if (key === undefined) {
|
|
||||||
blueslip.error("Tried to call a Dict method with an undefined key.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const str_key = ':' + key.toString();
|
|
||||||
return this._fold_case ? str_key.toLowerCase() : str_key;
|
|
||||||
}
|
|
||||||
|
|
||||||
clone(): Dict<K, V> {
|
clone(): Dict<K, V> {
|
||||||
const dict = new Dict<K, V>({fold_case: this._fold_case});
|
const dict = new Dict<K, V>({fold_case: this._fold_case});
|
||||||
dict._items = { ...this._items };
|
dict._items = { ...this._items };
|
||||||
|
@ -83,7 +73,7 @@ export class Dict<K, V> {
|
||||||
get(key: K): V | undefined {
|
get(key: K): V | undefined {
|
||||||
const mapping = this._items[this._munge(key)];
|
const mapping = this._items[this._munge(key)];
|
||||||
if (mapping === undefined) {
|
if (mapping === undefined) {
|
||||||
return;
|
return undefined;
|
||||||
}
|
}
|
||||||
return mapping.v;
|
return mapping.v;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +113,7 @@ export class Dict<K, V> {
|
||||||
|
|
||||||
items(): [K, V][] {
|
items(): [K, V][] {
|
||||||
return _.map(_.values(this._items),
|
return _.map(_.values(this._items),
|
||||||
(mapping: KeyValue<K, V>): [K, V] => [mapping.k, mapping.v]);
|
(mapping: KeyValue<K, V>): [K, V] => [mapping.k, mapping.v]);
|
||||||
}
|
}
|
||||||
|
|
||||||
num_items(): number {
|
num_items(): number {
|
||||||
|
@ -134,11 +124,21 @@ export class Dict<K, V> {
|
||||||
return _.isEmpty(this._items);
|
return _.isEmpty(this._items);
|
||||||
}
|
}
|
||||||
|
|
||||||
each(f: (v: V, k?: K) => void) {
|
each(f: (v: V, k?: K) => void): void {
|
||||||
_.each(this._items, (mapping: KeyValue<K, V>) => f(mapping.v, mapping.k));
|
_.each(this._items, (mapping: KeyValue<K, V>) => f(mapping.v, mapping.k));
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear(): void {
|
||||||
this._items = {};
|
this._items = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle case-folding of keys and the empty string.
|
||||||
|
private _munge(key: K): string | undefined {
|
||||||
|
if (key === undefined) {
|
||||||
|
blueslip.error("Tried to call a Dict method with an undefined key.");
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const str_key = ':' + key.toString();
|
||||||
|
return this._fold_case ? str_key.toLowerCase() : str_key;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
import { basename } from 'path';
|
import { basename } from 'path';
|
||||||
|
|
||||||
|
interface Loader {
|
||||||
|
test: string;
|
||||||
|
use: string;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return imports-loader format to the config
|
/* Return imports-loader format to the config
|
||||||
For example:
|
For example:
|
||||||
[
|
[
|
||||||
|
@ -7,11 +12,11 @@ import { basename } from 'path';
|
||||||
{path: './foler/my_module.js', args: '?this=>window'},
|
{path: './foler/my_module.js', args: '?this=>window'},
|
||||||
]
|
]
|
||||||
*/
|
*/
|
||||||
interface importLoaderOptions {
|
interface ImportLoaderOptions {
|
||||||
path: string;
|
path: string;
|
||||||
args: string;
|
args: string;
|
||||||
}
|
}
|
||||||
function getImportLoaders(optionsArr:Array<importLoaderOptions>) {
|
function getImportLoaders(optionsArr: ImportLoaderOptions[]): Loader[] {
|
||||||
const importsLoaders = [];
|
const importsLoaders = [];
|
||||||
for (var loaderEntry of optionsArr) {
|
for (var loaderEntry of optionsArr) {
|
||||||
importsLoaders.push({
|
importsLoaders.push({
|
||||||
|
@ -34,11 +39,11 @@ function getImportLoaders(optionsArr:Array<importLoaderOptions>) {
|
||||||
{path: './folder/my_module.js', name: ['name1', 'name2']}
|
{path: './folder/my_module.js', name: ['name1', 'name2']}
|
||||||
]
|
]
|
||||||
*/
|
*/
|
||||||
interface exportLoaderOptions {
|
interface ExportLoaderOptions {
|
||||||
path: string;
|
path: string;
|
||||||
name?: string | Array<string>;
|
name?: string | string[];
|
||||||
}
|
}
|
||||||
function getExposeLoaders(optionsArr:Array<exportLoaderOptions>) {
|
function getExposeLoaders(optionsArr: ExportLoaderOptions[]): Loader[] {
|
||||||
const exposeLoaders = [];
|
const exposeLoaders = [];
|
||||||
for (var loaderEntry of optionsArr) {
|
for (var loaderEntry of optionsArr) {
|
||||||
const path = loaderEntry.path;
|
const path = loaderEntry.path;
|
||||||
|
|
|
@ -2,12 +2,12 @@ import { resolve } from 'path';
|
||||||
import * as BundleTracker from 'webpack-bundle-tracker';
|
import * as BundleTracker from 'webpack-bundle-tracker';
|
||||||
import * as webpack from 'webpack';
|
import * as webpack from 'webpack';
|
||||||
import { getExposeLoaders, getImportLoaders } from './webpack-helpers';
|
import { getExposeLoaders, getImportLoaders } from './webpack-helpers';
|
||||||
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
import * as MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
||||||
|
|
||||||
const assets = require('./webpack.assets.json');
|
const assets = require('./webpack.assets.json');
|
||||||
|
|
||||||
// Adds on css-hot-loader in dev mode
|
// Adds on css-hot-loader in dev mode
|
||||||
function getHotCSS(bundle:any[], isProd:boolean) {
|
function getHotCSS(bundle: any[], isProd: boolean): any[] {
|
||||||
if (isProd) {
|
if (isProd) {
|
||||||
return bundle;
|
return bundle;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ function getHotCSS(bundle:any[], isProd:boolean) {
|
||||||
].concat(bundle);
|
].concat(bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (env?: string) : webpack.Configuration => {
|
export default (env?: string): webpack.Configuration => {
|
||||||
const production: boolean = env === "production";
|
const production: boolean = env === "production";
|
||||||
const config: webpack.Configuration = {
|
const config: webpack.Configuration = {
|
||||||
mode: production ? "production" : "development",
|
mode: production ? "production" : "development",
|
||||||
|
|
Loading…
Reference in New Issue