Emmet strict mode move, part 2 (#37840)

Continue moving emmet extension to strict mode. This change does the following:

- Remove jsdoc types. These are unused in ts files and can easily get out of date
- Annotate when something can return undefined
- Add null checks for when something can be undefined
- Add explicit types when something can be any
This commit is contained in:
Matt Bierner
2017-11-20 14:08:49 -08:00
committed by GitHub
parent c93e6c60ab
commit 7965160a6d
13 changed files with 85 additions and 103 deletions

View File

@@ -15,9 +15,8 @@ const reAbsolute = /^\/+/;
/**
* Locates given `filePath` on users file system and returns absolute path to it.
* This method expects either URL, or relative/absolute path to resource
* @param {String} basePath Base path to use if filePath is not absoulte
* @param {String} filePath File to locate.
* @return {Promise}
* @param basePath Base path to use if filePath is not absoulte
* @param filePath File to locate.
*/
export function locateFile(base: string, filePath: string): Promise<string> {
if (/^\w+:/.test(filePath)) {
@@ -34,26 +33,20 @@ export function locateFile(base: string, filePath: string): Promise<string> {
/**
* Resolves relative file path
* @param {TextEditor|String} base
* @param {String} filePath
* @return {Promise}
*/
function resolveRelative(basePath, filePath): Promise<string> {
function resolveRelative(basePath: string, filePath: string): Promise<string> {
return tryFile(path.resolve(basePath, filePath));
}
/**
* Resolves absolute file path agaist given editor: tries to find file in every
* parent of editors file
* @param {TextEditor|String} base
* @param {String} filePath
* @return {Promise}
*/
function resolveAbsolute(basePath, filePath): Promise<string> {
function resolveAbsolute(basePath: string, filePath: string): Promise<string> {
return new Promise((resolve, reject) => {
filePath = filePath.replace(reAbsolute, '');
const next = ctx => {
const next = (ctx: string) => {
tryFile(path.resolve(ctx, filePath))
.then(resolve, err => {
const dir = path.dirname(ctx);
@@ -71,10 +64,8 @@ function resolveAbsolute(basePath, filePath): Promise<string> {
/**
* Check if given file exists and its a file, not directory
* @param {String} file
* @return {Promise}
*/
function tryFile(file): Promise<string> {
function tryFile(file: string): Promise<string> {
return new Promise((resolve, reject) => {
fs.stat(file, (err, stat) => {
if (err) {