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

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbirtles committed Jul 11, 2019
1 parent 3b0eaa5 commit f339003
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 206 deletions.
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,20 @@
},
"dependencies": {
"cosmiconfig": "^4.0.0",
"estree-walker": "^0.6.1",
"lodash": "^4.17.10",
"prettier": "1.17.0",
"prettier-plugin-svelte": "0.5.1",
"magic-string": "^0.25.3",
"prettier": "1.18.2",
"prettier-plugin-svelte": "0.7.0",
"sinon": "^4.5.0",
"source-map": "^0.7.3",
"svelte": "3.2.0",
"typescript": "3.4.5",
"vscode-css-languageservice": "3.0.13",
"svelte": "3.6.7",
"typescript": "3.5.3",
"vscode-css-languageservice": "4.0.2",
"vscode-emmet-helper": "1.2.15",
"vscode-html-languageservice": "2.1.12",
"vscode-html-languageservice": "3.0.2",
"vscode-languageserver": "5.2.1",
"vscode-languageserver-types": "3.14.0",
"vscode-uri": "1.0.6"
"vscode-uri": "2.0.3"
}
}
139 changes: 0 additions & 139 deletions src/modules.d.ts

This file was deleted.

47 changes: 26 additions & 21 deletions src/plugins/SveltePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import {
} from '../api';
import { SvelteDocument } from '../lib/documents/SvelteDocument';
import { RawSourceMap, RawIndexMap, SourceMapConsumer } from 'source-map';
import { PreprocessOptions, CompileOptions, Warning } from 'svelte/compiler';
import { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
import { importSvelte, getSveltePackageInfo } from './svelte/sveltePackage';
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';

interface SvelteConfig extends CompileOptions {
preprocess?: PreprocessOptions;
preprocess?: PreprocessorGroup;
}

const DEFAULT_OPTIONS: CompileOptions = {
Expand Down Expand Up @@ -47,28 +48,32 @@ export class SveltePlugin implements DiagnosticsProvider, FormattingProvider {
let source = document.getText();

const config = await this.loadConfig(document.getFilePath()!);
const svelte = importSvelte(document.getFilePath()!) as any;
const svelte = importSvelte(document.getFilePath()!);

const preprocessor = makePreprocessor(document as SvelteDocument, config.preprocess);
source = (await svelte.preprocess(source, preprocessor, {filename: document.getFilePath()})).toString();
source = (await svelte.preprocess(source, preprocessor, {
filename: document.getFilePath()!,
})).toString();
preprocessor.transpiledDocument.setText(source);

let diagnostics: Diagnostic[];
try {
delete config.preprocess;
const res = svelte.compile(source, config);

diagnostics = ((res.stats.warnings || res.warnings || []) as Warning[]).map(warning => {
const start = warning.start || { line: 1, column: 0 };
const end = warning.end || start;
return {
range: Range.create(start.line - 1, start.column, end.line - 1, end.column),
message: warning.message,
severity: DiagnosticSeverity.Warning,
source: 'svelte',
code: warning.code,
};
});
diagnostics = (((res.stats as any).warnings || res.warnings || []) as Warning[]).map(
warning => {
const start = warning.start || { line: 1, column: 0 };
const end = warning.end || start;
return {
range: Range.create(start.line - 1, start.column, end.line - 1, end.column),
message: warning.message,
severity: DiagnosticSeverity.Warning,
source: 'svelte',
code: warning.code,
};
},
);
} catch (err) {
const start = err.start || { line: 1, column: 0 };
const end = err.end || start;
Expand Down Expand Up @@ -120,7 +125,7 @@ export class SveltePlugin implements DiagnosticsProvider, FormattingProvider {
}
}

interface Preprocessor extends PreprocessOptions {
interface Preprocessor extends PreprocessorGroup {
fragments: {
source: Fragment;
transpiled: Fragment;
Expand All @@ -130,14 +135,14 @@ interface Preprocessor extends PreprocessOptions {
transpiledDocument: SvelteDocument;
}

function makePreprocessor(document: SvelteDocument, preprocessors: PreprocessOptions = {}) {
function makePreprocessor(document: SvelteDocument, preprocessors: PreprocessorGroup = {}) {
const preprocessor: Preprocessor = {
fragments: [],
transpiledDocument: new SvelteDocument(document.getURL(), document.getText()),
};

if (preprocessors.script) {
preprocessor.script = async args => {
preprocessor.script = (async (args: any) => {
const res = await preprocessors.script!(args);
if (res && res.map) {
preprocessor.fragments.push({
Expand All @@ -148,11 +153,11 @@ function makePreprocessor(document: SvelteDocument, preprocessors: PreprocessOpt
});
}
return res;
};
}) as any;
}

if (preprocessors.style) {
preprocessor.style = async args => {
preprocessor.style = (async (args: any) => {
const res = await preprocessors.style!(args);
if (res && res.map) {
preprocessor.fragments.push({
Expand All @@ -163,7 +168,7 @@ function makePreprocessor(document: SvelteDocument, preprocessors: PreprocessOpt
});
}
return res;
};
}) as any;
}

return preprocessor;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/svelte/sveltePackage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dirname, resolve } from 'path';
import * as svelte from 'svelte/compiler';

export function getSveltePackageInfo(fromPath: string) {
const packageJSONPath = require.resolve('svelte/package.json', {
Expand All @@ -18,7 +19,7 @@ export function getSveltePackageInfo(fromPath: string) {
};
}

export function importSvelte(fromPath: string) {
export function importSvelte(fromPath: string): typeof svelte {
const pkg = getSveltePackageInfo(fromPath);

let main = pkg.path;
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import URL from 'vscode-uri';
import { URI } from 'vscode-uri';

export function clamp(num: number, min: number, max: number): number {
return Math.max(min, Math.min(max, num));
}

export function urlToPath(stringUrl: string): string | null {
const url = URL.parse(stringUrl);
const url = URI.parse(stringUrl);
if (url.scheme !== 'file') {
return null;
}
return url.fsPath.replace(/\\/g, '/');
}

export function pathToUrl(path: string) {
return URL.file(path).toString();
return URI.file(path).toString();
}

export function flatten<T>(arr: T[][]): T[] {
Expand Down
Loading

0 comments on commit f339003

Please sign in to comment.