Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #28 from mjbvz/upgrade-to-ts2
Browse files Browse the repository at this point in the history
Upgrade to TypeScript 2 and Fix a few Null Dereference Errors
  • Loading branch information
cssho authored Mar 12, 2017
2 parents 2e906bc + f4a3257 commit ad8dd91
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "1.3.1",
"publisher": "cssho",
"engines": {
"vscode": "^0.10.8"
"vscode": "^1.9.0"
},
"categories": [
"Other"
Expand Down Expand Up @@ -87,13 +87,15 @@
}
},
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"devDependencies": {
"typescript": "^1.7.5",
"vscode": "^0.11.1"
"@types/mocha": "2.2.39",
"@types/node": "^7.0.5",
"typescript": "^2.2.1",
"vscode": "^1.0.4"
},
"dependencies": {
"copy-paste": "^1.1.4",
Expand Down
22 changes: 14 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export function activate(context: vscode.ExtensionContext) {
let registration = vscode.workspace.registerTextDocumentContentProvider('svg-preview', provider);

vscode.workspace.onDidChangeTextDocument((e: vscode.TextDocumentChangeEvent) => {
if (e.document === vscode.window.activeTextEditor.document && !checkNoSvg(vscode.window.activeTextEditor.document, false)) {
provider.update(previewUri);
if (vscode.window.activeTextEditor) {
if (e.document === vscode.window.activeTextEditor.document && !checkNoSvg(vscode.window.activeTextEditor.document, false)) {
provider.update(previewUri);
}
}
});

Expand All @@ -47,17 +49,20 @@ export function activate(context: vscode.ExtensionContext) {
let saveas = vscode.commands.registerTextEditorCommand('svgviewer.saveas', (te, t) => {
if (checkNoSvg(te.document)) return;
let editor = vscode.window.activeTextEditor;
let text = editor.document.getText();
let tmpobj = tmp.fileSync({ 'postfix': '.svg' });
let pngpath = editor.document.uri.fsPath.replace('.svg', '.png');
exportPng(tmpobj, text, pngpath);
if (editor) {
let text = editor.document.getText();
let tmpobj = tmp.fileSync({ 'postfix': '.svg' });
let pngpath = editor.document.uri.fsPath.replace('.svg', '.png');
exportPng(tmpobj, text, pngpath);
}
});

context.subscriptions.push(saveas);

let saveassize = vscode.commands.registerTextEditorCommand('svgviewer.saveassize', (te, t) => {
if (checkNoSvg(te.document)) return;
let editor = vscode.window.activeTextEditor;
if (!editor) return;
let text = editor.document.getText();
let tmpobj = tmp.fileSync({ 'postfix': '.svg' });
let pngpath = editor.document.uri.fsPath.replace('.svg', '.png');
Expand All @@ -79,6 +84,7 @@ export function activate(context: vscode.ExtensionContext) {
let copydu = vscode.commands.registerTextEditorCommand('svgviewer.copydui', (te, t) => {
if (checkNoSvg(te.document)) return;
let editor = vscode.window.activeTextEditor;
if (!editor) return;
let text = editor.document.getText();
cp.copy('data:image/svg+xml,' + encodeURIComponent(text));
});
Expand All @@ -95,7 +101,7 @@ export function activate(context: vscode.ExtensionContext) {
});

vscode.workspace.onDidChangeTextDocument((event: vscode.TextDocumentChangeEvent) => {
if (event.document === vscode.window.activeTextEditor.document) {
if (vscode.window.activeTextEditor && event.document === vscode.window.activeTextEditor.document) {
exportProvider.update(makeExportUri(event.document.uri));
}
});
Expand Down Expand Up @@ -143,7 +149,7 @@ function checkNoSvg(document: vscode.TextDocument, displayMessage: boolean = tru
return isNGType;
}

function checkSizeInput(value: string): string {
function checkSizeInput(value: string): string | null {
return value !== '' && !isNaN(Number(value)) && Number(value) > 0
? null : 'Please set number.';
}
Expand Down
2 changes: 1 addition & 1 deletion src/svgProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class SvgDocumentContentProvider implements vscode.TextDocumentContentPro

private extractSnippet(): string {
let editor = vscode.window.activeTextEditor;
let text = editor.document.getText();
let text = editor ? editor.document.getText() : '';
return this.snippet(text);
}

Expand Down
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
"module": "commonjs",
"target": "es5",
"outDir": "out",
"noLib": true,
"lib": [
"es2015"
],
"sourceMap": true,
"rootDir": "."
"rootDir": ".",
"strictNullChecks": true
},
"exclude": [
"node_modules"
Expand Down
1 change: 0 additions & 1 deletion typings/node.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion typings/vscode-typings.d.ts

This file was deleted.

0 comments on commit ad8dd91

Please sign in to comment.