Start moving html ext to strict mode compile

Moves the html extension's client code to strict mode and also updates some of the server code. The rest of this migration will requires changes to the *.d.ts files that the server consumes
This commit is contained in:
Matt Bierner 2017-11-06 15:19:34 -08:00
parent e5b9b820ef
commit 62aa6cb900
9 changed files with 31 additions and 36 deletions

View file

@ -32,7 +32,7 @@ export function activate(context: ExtensionContext) {
let toDispose = context.subscriptions;
let packageInfo = getPackageInfo(context);
let telemetryReporter: TelemetryReporter = packageInfo && new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey);
let telemetryReporter: TelemetryReporter | null = packageInfo && new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey);
if (telemetryReporter) {
toDispose.push(telemetryReporter);
}
@ -166,7 +166,7 @@ export function activate(context: ExtensionContext) {
});
}
function getPackageInfo(context: ExtensionContext): IPackageInfo {
function getPackageInfo(context: ExtensionContext): IPackageInfo | null {
let extensionPackage = require(context.asAbsolutePath('./package.json'));
if (extensionPackage) {
return {

View file

@ -15,7 +15,7 @@ export function activateTagClosing(tagProvider: (document: TextDocument, positio
updateEnabledState();
window.onDidChangeActiveTextEditor(updateEnabledState, null, disposables);
let timeout: NodeJS.Timer = void 0;
let timeout: NodeJS.Timer | undefined = void 0;
function updateEnabledState() {
isEnabled = false;
@ -56,13 +56,15 @@ export function activateTagClosing(tagProvider: (document: TextDocument, positio
tagProvider(document, position).then(text => {
if (text && isEnabled) {
let activeEditor = window.activeTextEditor;
let activeDocument = activeEditor && activeEditor.document;
if (document === activeDocument && activeDocument.version === version) {
let selections = activeEditor.selections;
if (selections.length && selections.some(s => s.active.isEqual(position))) {
activeEditor.insertSnippet(new SnippetString(text), selections.map(s => s.active));
} else {
activeEditor.insertSnippet(new SnippetString(text), position);
if (activeEditor) {
let activeDocument = activeEditor.document;
if (document === activeDocument && activeDocument.version === version) {
let selections = activeEditor.selections;
if (selections.length && selections.some(s => s.active.isEqual(position))) {
activeEditor.insertSnippet(new SnippetString(text), selections.map(s => s.active));
} else {
activeEditor.insertSnippet(new SnippetString(text), position);
}
}
}
}

View file

@ -1,11 +0,0 @@
declare module "color-convert" {
module convert {
module rgb {
function hex(r: number, g: number, b: number);
function hsl(r: number, g: number, b: number);
function hvs(r: number, g: number, b: number);
}
}
export = convert;
}

View file

@ -5,6 +5,7 @@
"outDir": "./out",
"lib": [
"es5", "es2015.promise"
]
],
"strict": true
}
}

View file

@ -29,9 +29,9 @@ export function getDocumentRegions(languageService: LanguageService, document: T
let regions: EmbeddedRegion[] = [];
let scanner = languageService.createScanner(document.getText());
let lastTagName: string;
let lastAttributeName: string;
let languageIdFromType: string;
let importedScripts = [];
let lastAttributeName: string | null;
let languageIdFromType: string | undefined = undefined;
let importedScripts: string[] = [];
let token = scanner.scan();
while (token !== TokenType.EOS) {
@ -224,7 +224,7 @@ function append(result: string, str: string, n: number): string {
return result;
}
function getAttributeLanguage(attributeName: string): string {
function getAttributeLanguage(attributeName: string): string | null {
let match = attributeName.match(/^(style)$|^(on\w+)$/i);
if (!match) {
return null;

View file

@ -60,7 +60,6 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService): LanguageM
if (offset > 0 && text.charAt(offset - 1).match(/[>\/]/g)) {
return htmlLanguageService.doTagComplete(document, position, htmlDocuments.get(document));
}
return null;
},
onDocumentRemoved(document: TextDocument) {
htmlDocuments.onDocumentRemoved(document);

View file

@ -73,7 +73,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
updateCurrentTextDocument(document);
const syntaxDiagnostics = jsLanguageService.getSyntacticDiagnostics(FILE_NAME);
const semanticDiagnostics = jsLanguageService.getSemanticDiagnostics(FILE_NAME);
return syntaxDiagnostics.concat(semanticDiagnostics).map((diag): Diagnostic => {
return syntaxDiagnostics.concat(semanticDiagnostics).map((diag: ts.Diagnostic): Diagnostic => {
return {
range: convertRange(currentTextDocument, diag),
severity: DiagnosticSeverity.Error,
@ -143,7 +143,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
let signature: SignatureInformation = {
label: '',
documentation: null,
documentation: undefined,
parameters: []
};
@ -185,7 +185,7 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
let items = jsLanguageService.getNavigationBarItems(FILE_NAME);
if (items) {
let result: SymbolInformation[] = [];
let existing = {};
let existing = Object.create(null);
let collectSymbols = (item: ts.NavigationBarItem, containerLabel?: string) => {
let sig = item.text + item.kind + item.spans[0].start;
if (item.kind !== 'script' && !existing[sig]) {
@ -288,9 +288,13 @@ export function getJavascriptMode(documentRegions: LanguageModelCache<HTMLDocume
};
};
function convertRange(document: TextDocument, span: { start: number, length: number }): Range {
let startPosition = document.positionAt(span.start);
let endPosition = document.positionAt(span.start + span.length);
function convertRange(document: TextDocument, span: { start: number | undefined, length: number | undefined }): Range {
if (typeof span.start === 'undefined') {
const pos = document.positionAt(0);
return Range.create(pos, pos);
}
const startPosition = document.positionAt(span.start);
const endPosition = document.positionAt(span.start + (span.length || 0));
return Range.create(startPosition, endPosition);
}

View file

@ -31,7 +31,7 @@ export interface SettingProvider {
}
export interface LanguageMode {
getId();
getId(): string;
configure?: (options: Settings) => void;
doValidation?: (document: TextDocument, settings?: Settings) => Diagnostic[];
doComplete?: (document: TextDocument, position: Position, settings?: Settings) => CompletionList;
@ -74,7 +74,7 @@ export function getLanguageModes(supportedLanguages: { [languageId: string]: boo
let modelCaches: LanguageModelCache<any>[] = [];
modelCaches.push(documentRegions);
let modes = {};
let modes = Object.create(null);
modes['html'] = getHTMLMode(htmlLanguageService);
if (supportedLanguages['css']) {
modes['css'] = getCSSMode(documentRegions);

View file

@ -27,7 +27,7 @@ suite('HTML Javascript Support', () => {
var mode = getJavascriptMode(documentRegions);
let position = document.positionAt(offset);
let list = mode.doComplete(document, position);
let list = mode.doComplete!(document, position);
assert.ok(list);
let actualLabels = list.items.map(c => c.label).sort();