diff --git a/.prettierignore b/.prettierignore index 6da7c2d95..adfbebbb1 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,5 +3,8 @@ packages/svelte2tsx/test/*/samples/*/*sx packages/svelte2tsx/test/*/samples/*/*.svelte packages/svelte2tsx/test/sourcemaps/*.html packages/language-server/test/**/*.svelte +packages/language-server/test/**/testfiles/**/*.ts packages/svelte-vscode/syntaxes/*.yaml +**/dist .github/** +.history/** diff --git a/.vscode/settings.json b/.vscode/settings.json index a5a37d2aa..f865d2f2c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "typescript.preferences.quoteStyle": "single", + "typescript.preferences.quoteStyle": "single" } diff --git a/README.md b/README.md index 25ee2883e..b3b4732e5 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,7 @@ A `.svelte` file would look something like this: } - +

{count} * 2 = {doubled}

{doubled} * 2 = {quadrupled}

@@ -128,7 +126,7 @@ For tricker issues, you can run the tests with a debugger in VSCode by setting a Svelte is an MIT-licensed open source project with its ongoing development made possible entirely by the support of awesome volunteers. If you'd like to support their efforts, please consider: -- [Becoming a backer on Open Collective](https://opencollective.com/svelte). +- [Becoming a backer on Open Collective](https://opencollective.com/svelte). Funds donated via Open Collective will be used for compensating expenses related to Svelte's development such as hosting costs. If sufficient donations are received, funds may also be used to support Svelte's development more directly. diff --git a/docs/README.md b/docs/README.md index 52200e769..4f42d85ac 100644 --- a/docs/README.md +++ b/docs/README.md @@ -39,9 +39,7 @@ LSP-compatible editors, you can use an HTML comment with the `@component` tag:
-

- Hello world -

+

Hello world

``` @@ -66,7 +64,7 @@ The VS Code extension comes with its own syntax highlighting grammar which defin } ``` -To find out the scope of the things you want to highlight differently, you can use the scope inspector by entering the command "Developer: Inspect Editor Tokens and Scopes". The scope at the top of the section "textmate scopes" is what you are looking for. The current color is in the section "foreground" - you can use this to look up colors of other scopes if you want them to be the same color but don't know the color-code. +To find out the scope of the things you want to highlight differently, you can use the scope inspector by entering the command "Developer: Inspect Editor Tokens and Scopes". The scope at the top of the section "textmate scopes" is what you are looking for. The current color is in the section "foreground" - you can use this to look up colors of other scopes if you want them to be the same color but don't know the color-code. For more info on customizing your theme, [see the VS Code docs](https://code.visualstudio.com/docs/getstarted/themes#_customizing-a-color-theme). @@ -95,8 +93,9 @@ If you have the `Babel Javascript` plugin installed, this may be the cause. Disa #### My Code does not get formatted Your default formatter for Svelte files may be wrong. -- Mabye it's set to the old Svelte extension, if so, remove the setting -- Maybe you set all files to be formatted by the prettier extension. Then you have two options: Either install `prettier-plugin-svelte` from npm, or tell VSCode to format the code with the `Svelte for VSCode extension`: + +- Mabye it's set to the old Svelte extension, if so, remove the setting +- Maybe you set all files to be formatted by the prettier extension. Then you have two options: Either install `prettier-plugin-svelte` from npm, or tell VSCode to format the code with the `Svelte for VSCode extension`: ```json "[svelte]": { diff --git a/docs/internal/deployment.md b/docs/internal/deployment.md index db4cf9dff..093d6f2ee 100644 --- a/docs/internal/deployment.md +++ b/docs/internal/deployment.md @@ -2,13 +2,13 @@ The [publisher is Svelte](https://marketplace.visualstudio.com/manage/publishers/svelte) -- Extension builds with the account signed up via GitHub from orta +- Extension builds with the account signed up via GitHub from orta ### npm deployments -- Deployments come from a bot: `svelte-language-tools-deploy` +- Deployments come from a bot: `svelte-language-tools-deploy` ### When Deployments happen -- Nightly builds are triggered through a scheduled GitHub workflow every night at 04:00 UTC. -- Production builds are triggered by creating a new tag, which is best done through the "do a release" on Github. The tag name equals the version that is then shown on the marketplace, so each tag should have a higher version than the previous. +- Nightly builds are triggered through a scheduled GitHub workflow every night at 04:00 UTC. +- Production builds are triggered by creating a new tag, which is best done through the "do a release" on Github. The tag name equals the version that is then shown on the marketplace, so each tag should have a higher version than the previous. diff --git a/docs/internal/overview.md b/docs/internal/overview.md index ea393e121..b9ff47fe2 100644 --- a/docs/internal/overview.md +++ b/docs/internal/overview.md @@ -52,7 +52,7 @@ We chose the second option because TypeScript provides a language service which `svelte2tsx` uses some [ambient definitions](/packages/svelte2tsx/svelte-shims.d.ts) which are loaded by the language server to do some of the transformations. It also provides [JSX definitions](/packages/svelte2tsx/svelte-jsx.d.ts) which are recognized by the TypeScript compiler and define intrinsic elements, attributes and events - so if you ever get an error that a DOM attribute is not assignable to a DOM element, it's likely a missing declaration in there. -The code generated by `svelte2tsx` is not runnable in any way and does not actually exist at runtime when you run your app, it purely exists for the IntelliSense. +The code generated by `svelte2tsx` is not runnable in any way and does not actually exist at runtime when you run your app, it purely exists for the IntelliSense. The code also returns source mappings so we know which position in the original code corresponds to which generated position. diff --git a/docs/preprocessors/in-general.md b/docs/preprocessors/in-general.md index 73b6877cb..348279a99 100644 --- a/docs/preprocessors/in-general.md +++ b/docs/preprocessors/in-general.md @@ -4,14 +4,14 @@ If a svelte file contains some language other than `html`, `css` or `javascript`, `svelte-vscode` needs to know how to [preprocess](https://svelte.dev/docs#svelte_preprocess) it. This can be achieved by creating a `svelte.config.js` file at the root of your project which exports a svelte options object (similar to `svelte-loader` and `rollup-plugin-svelte`). It's recommended to use the official [svelte-preprocess](https://github.com/sveltejs/svelte-preprocess) package which can handle many languages. -> NOTE: you __cannot__ use the new `import x from y` and `export const` / `export default` syntax in `svelte.config.js`. +> NOTE: you **cannot** use the new `import x from y` and `export const` / `export default` syntax in `svelte.config.js`. ```js // svelte.config.js const sveltePreprocess = require('svelte-preprocess'); module.exports = { - preprocess: sveltePreprocess(), + preprocess: sveltePreprocess() }; ``` @@ -46,9 +46,9 @@ const sveltePreprocess = require('svelte-preprocess'); module.exports = { preprocess: sveltePreprocess({ defaults: { - script: 'typescript', // <-- now you can just write - }, - }), + script: 'typescript' // <-- now you can just write + } + }) }; ``` @@ -63,14 +63,14 @@ const sveltePreprocess = require('svelte-preprocess'); // using sourceMap as an example, but could be anything you need dynamically function createPreprocessors(sourceMap) { return sveltePreprocess({ - sourceMap, + sourceMap // ... your settings }); } module.exports = { preprocess: createPreprocessors(true), - createPreprocessors, + createPreprocessors }; ``` @@ -88,10 +88,10 @@ export default { // ... svelte({ // ... - preprocess: createPreprocessors(!production), - }), + preprocess: createPreprocessors(!production) + }) // ... - ], + ] }; ``` diff --git a/docs/preprocessors/scss-less.md b/docs/preprocessors/scss-less.md index ae417901d..c185032d7 100644 --- a/docs/preprocessors/scss-less.md +++ b/docs/preprocessors/scss-less.md @@ -27,7 +27,7 @@ You need a `svelte.config.js`. [Read here on how to set it up and also how it re const sveltePreprocess = require('svelte-preprocess'); module.exports = { - preprocess: sveltePreprocess(), + preprocess: sveltePreprocess() }; ``` @@ -76,6 +76,6 @@ const sveltePreprocess = require('svelte-preprocess'); const path = require('path'); module.exports = { - preprocess: sveltePreprocess({ includePaths: [path.join(__dirname, 'relative/path')] }) + preprocess: sveltePreprocess({ includePaths: [path.join(__dirname, 'relative/path')] }) }; ``` diff --git a/docs/preprocessors/typescript.md b/docs/preprocessors/typescript.md index 2c7db4a0d..656a04e93 100644 --- a/docs/preprocessors/typescript.md +++ b/docs/preprocessors/typescript.md @@ -32,7 +32,7 @@ You may optionally want to add a `svelte.config.js` file - but it is not require const sveltePreprocess = require('svelte-preprocess'); module.exports = { - preprocess: sveltePreprocess(), + preprocess: sveltePreprocess() }; ``` diff --git a/package.json b/package.json index cd23b87d1..305552fcf 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,10 @@ "build": "tsc -b", "test": "CI=true yarn workspaces run test", "watch": "tsc -b -watch", - "lint": "eslint \"packages/**/*.{ts,js}\"" + "format": "prettier --write .", + "lint": "prettier --check . && eslint \"packages/**/*.{ts,js}\"" }, "dependencies": { - "axios": "0.21.1", "typescript": "^4.1.3" }, "devDependencies": { @@ -24,6 +24,7 @@ "@typescript-eslint/parser": "^4.3.0", "eslint": "^7.7.0", "eslint-plugin-import": "^2.22.1", - "eslint-plugin-svelte3": "^2.7.3" + "eslint-plugin-svelte3": "^2.7.3", + "prettier": "2.2.1" } } diff --git a/packages/language-server/src/ls-config.ts b/packages/language-server/src/ls-config.ts index b82019819..164fd167f 100644 --- a/packages/language-server/src/ls-config.ts +++ b/packages/language-server/src/ls-config.ts @@ -107,7 +107,7 @@ export interface LSTypescriptConfig { }; semanticTokens: { enable: boolean; - } + }; } export interface LSCSSConfig { diff --git a/packages/language-server/src/plugins/css/features/svelte-selectors.ts b/packages/language-server/src/plugins/css/features/svelte-selectors.ts index ac13c13c8..f27a10a0d 100644 --- a/packages/language-server/src/plugins/css/features/svelte-selectors.ts +++ b/packages/language-server/src/plugins/css/features/svelte-selectors.ts @@ -3,8 +3,7 @@ import { IPseudoClassData } from 'vscode-css-languageservice'; export const pesudoClass: IPseudoClassData[] = [ { name: ':global()', - description: -`[svelte] :global modifier + description: `[svelte] :global modifier Applying styles to a selector globally`, references: [ diff --git a/packages/language-server/src/plugins/css/service.ts b/packages/language-server/src/plugins/css/service.ts index 11629a03d..30c704886 100644 --- a/packages/language-server/src/plugins/css/service.ts +++ b/packages/language-server/src/plugins/css/service.ts @@ -22,10 +22,15 @@ const customDataProvider: ICSSDataProvider = { } }; -const [css, scss, less] = [getCSSLanguageService, getSCSSLanguageService, getLESSLanguageService] - .map(getService => getService({ +const [css, scss, less] = [ + getCSSLanguageService, + getSCSSLanguageService, + getLESSLanguageService +].map((getService) => + getService({ customDataProviders: [customDataProvider] - })); + }) +); const langs = { css, diff --git a/packages/language-server/src/plugins/html/dataProvider.ts b/packages/language-server/src/plugins/html/dataProvider.ts index d20a57565..14947face 100644 --- a/packages/language-server/src/plugins/html/dataProvider.ts +++ b/packages/language-server/src/plugins/html/dataProvider.ts @@ -221,7 +221,7 @@ const mediaAttributes: IAttributeData[] = [ }, { name: 'bind:playbackRate', - description: 'how fast or slow to play the video, where 1 is \'normal\'' + description: "how fast or slow to play the video, where 1 is 'normal'" }, { name: 'bind:paused' @@ -256,14 +256,14 @@ const addAttributes: Record = { { name: 'bind:value' }, { name: 'bind:group', description: 'Available for type="radio" and type="checkbox"' }, indeterminateAttribute, - {...indeterminateAttribute, name: 'bind:indeterminate'} + { ...indeterminateAttribute, name: 'bind:indeterminate' } ], textarea: [{ name: 'bind:value' }], video: [...mediaAttributes, ...videoAttributes], audio: [...mediaAttributes] }; -const html5Tags = htmlData.tags!.map(tag => { +const html5Tags = htmlData.tags!.map((tag) => { let attributes = tag.attributes.map(mapToSvelteEvent); if (addAttributes[tag.name]) { attributes = [...attributes, ...addAttributes[tag.name]]; diff --git a/packages/language-server/src/plugins/typescript/LSAndTSDocResolver.ts b/packages/language-server/src/plugins/typescript/LSAndTSDocResolver.ts index 76a754f4c..87d15b7d5 100644 --- a/packages/language-server/src/plugins/typescript/LSAndTSDocResolver.ts +++ b/packages/language-server/src/plugins/typescript/LSAndTSDocResolver.ts @@ -103,8 +103,10 @@ export class LSAndTSDocResolver { } private getUserPreferences(scriptKind: ts.ScriptKind): ts.UserPreferences { - const configLang = scriptKind === ts.ScriptKind.TS || scriptKind === ts.ScriptKind.TSX - ? 'typescript' : 'javascript'; + const configLang = + scriptKind === ts.ScriptKind.TS || scriptKind === ts.ScriptKind.TSX + ? 'typescript' + : 'javascript'; return this.configManager.getTsUserPreferences(configLang); } diff --git a/packages/language-server/src/plugins/typescript/features/SelectionRangeProvider.ts b/packages/language-server/src/plugins/typescript/features/SelectionRangeProvider.ts index f64646a59..462fdced4 100644 --- a/packages/language-server/src/plugins/typescript/features/SelectionRangeProvider.ts +++ b/packages/language-server/src/plugins/typescript/features/SelectionRangeProvider.ts @@ -36,9 +36,7 @@ export class SelectionRangeProviderImpl implements SelectionRangeProvider { }; } - private filterOutUnmappedRange( - selectionRange: SelectionRange - ): SelectionRange | null { + private filterOutUnmappedRange(selectionRange: SelectionRange): SelectionRange | null { const flattened = this.flattenAndReverseSelectionRange(selectionRange); const filtered = flattened.filter((range) => range.start.line > 0 && range.end.line > 0); if (!filtered.length) { @@ -54,7 +52,6 @@ export class SelectionRangeProviderImpl implements SelectionRangeProvider { return result ?? null; } - /** * flatten the selection range and its parent to an array in reverse order * so it's easier to filter out unmapped selection and create a new tree of diff --git a/packages/language-server/src/plugins/typescript/features/SemanticTokensProvider.ts b/packages/language-server/src/plugins/typescript/features/SemanticTokensProvider.ts index 57be29d0b..9361cb6e9 100644 --- a/packages/language-server/src/plugins/typescript/features/SemanticTokensProvider.ts +++ b/packages/language-server/src/plugins/typescript/features/SemanticTokensProvider.ts @@ -1,9 +1,5 @@ import ts from 'typescript'; -import { - Range, - SemanticTokens, - SemanticTokensBuilder -} from 'vscode-languageserver'; +import { Range, SemanticTokens, SemanticTokensBuilder } from 'vscode-languageserver'; import { Document } from '../../../lib/documents'; import { SemanticTokensProvider } from '../../interfaces'; import { SnapshotFragment } from '../DocumentSnapshot'; @@ -65,7 +61,7 @@ export class SemanticTokensProviderImpl implements SemanticTokensProvider { const modifier = this.getTokenModifierFromClassification(encodedClassification); - builder.push(line, character, length, classificationType , modifier); + builder.push(line, character, length, classificationType, modifier); } return builder.build(); diff --git a/packages/language-server/src/plugins/typescript/features/SignatureHelpProvider.ts b/packages/language-server/src/plugins/typescript/features/SignatureHelpProvider.ts index f8b7355c8..daa2e44be 100644 --- a/packages/language-server/src/plugins/typescript/features/SignatureHelpProvider.ts +++ b/packages/language-server/src/plugins/typescript/features/SignatureHelpProvider.ts @@ -14,7 +14,7 @@ import { LSAndTSDocResolver } from '../LSAndTSDocResolver'; import { getMarkdownDocumentation } from '../previewer'; export class SignatureHelpProviderImpl implements SignatureHelpProvider { - constructor(private readonly lsAndTsDocResolver: LSAndTSDocResolver) { } + constructor(private readonly lsAndTsDocResolver: LSAndTSDocResolver) {} private static readonly triggerCharacters = ['(', ',', '<']; private static readonly retriggerCharacters = [')']; @@ -41,8 +41,7 @@ export class SignatureHelpProviderImpl implements SignatureHelpProvider { return null; } - const signatures = info.items - .map(this.toSignatureHelpInformation); + const signatures = info.items.map(this.toSignatureHelpInformation); return { signatures, @@ -134,18 +133,19 @@ export class SignatureHelpProviderImpl implements SignatureHelpProvider { return { label: prefixLabel + signatureLabel + suffixLabel, - documentation: signatureDocumentation ? { - value: signatureDocumentation, - kind: MarkupKind.Markdown - } : undefined, + documentation: signatureDocumentation + ? { + value: signatureDocumentation, + kind: MarkupKind.Markdown + } + : undefined, parameters }; } - private isInSvelte2tsxGeneratedFunction( - signatureHelpItem: ts.SignatureHelpItem - ) { - return signatureHelpItem.prefixDisplayParts - .some((part) => part.text.includes('__sveltets')); + private isInSvelte2tsxGeneratedFunction(signatureHelpItem: ts.SignatureHelpItem) { + return signatureHelpItem.prefixDisplayParts.some((part) => + part.text.includes('__sveltets') + ); } } diff --git a/packages/language-server/src/plugins/typescript/features/getDirectiveCommentCompletions.ts b/packages/language-server/src/plugins/typescript/features/getDirectiveCommentCompletions.ts index 5bd8691e6..825a9e4d0 100644 --- a/packages/language-server/src/plugins/typescript/features/getDirectiveCommentCompletions.ts +++ b/packages/language-server/src/plugins/typescript/features/getDirectiveCommentCompletions.ts @@ -15,8 +15,7 @@ import { export const tsDirectives = [ { value: '@ts-check', - description: - 'Enables semantic checking in a JavaScript file. Must be at the top of a file.' + description: 'Enables semantic checking in a JavaScript file. Must be at the top of a file.' }, { value: '@ts-nocheck', diff --git a/packages/language-server/src/plugins/typescript/svelte-sys.ts b/packages/language-server/src/plugins/typescript/svelte-sys.ts index d14bcdb9c..6393c0c30 100644 --- a/packages/language-server/src/plugins/typescript/svelte-sys.ts +++ b/packages/language-server/src/plugins/typescript/svelte-sys.ts @@ -18,13 +18,7 @@ export function createSvelteSys(getSnapshot: (fileName: string) => DocumentSnaps readDirectory(path, extensions, exclude, include, depth) { const extensionsWithSvelte = (extensions ?? []).concat('.svelte'); - return ts.sys.readDirectory( - path, - extensionsWithSvelte, - exclude, - include, - depth - ); + return ts.sys.readDirectory(path, extensionsWithSvelte, exclude, include, depth); } }; diff --git a/packages/language-server/src/plugins/typescript/utils.ts b/packages/language-server/src/plugins/typescript/utils.ts index 32408d220..112adc6cc 100644 --- a/packages/language-server/src/plugins/typescript/utils.ts +++ b/packages/language-server/src/plugins/typescript/utils.ts @@ -111,7 +111,7 @@ export function findTsConfigPath(fileName: string, rootUris: string[]) { ts.findConfigFile(searchDir, ts.sys.fileExists, 'jsconfig.json') || ''; // Don't return config files that exceed the current workspace context. - return !!path && rootUris.some(rootUri => isSubPath(rootUri, path)) ? path : ''; + return !!path && rootUris.some((rootUri) => isSubPath(rootUri, path)) ? path : ''; } export function isSubPath(uri: string, possibleSubPath: string): boolean { diff --git a/packages/language-server/test/plugins/svelte/features/getSelectionRange.test.ts b/packages/language-server/test/plugins/svelte/features/getSelectionRange.test.ts index d1991aab9..52280ea71 100644 --- a/packages/language-server/test/plugins/svelte/features/getSelectionRange.test.ts +++ b/packages/language-server/test/plugins/svelte/features/getSelectionRange.test.ts @@ -6,10 +6,7 @@ import { SvelteDocument } from '../../../../src/plugins/svelte/SvelteDocument'; describe('SveltePlugin#getSelectionRange', () => { const CURSOR = '|'; - async function expectToEqual( - contentWithCursor: string, - expected: SelectionRange | null - ) { + async function expectToEqual(contentWithCursor: string, expected: SelectionRange | null) { const svelteDoc = new SvelteDocument( new Document('url', contentWithCursor.replace(CURSOR, '')) ); diff --git a/packages/language-server/test/plugins/typescript/features/HoverProvider.test.ts b/packages/language-server/test/plugins/typescript/features/HoverProvider.test.ts index 38015a33a..7e0bfce16 100644 --- a/packages/language-server/test/plugins/typescript/features/HoverProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/HoverProvider.test.ts @@ -87,8 +87,7 @@ describe('HoverProvider', () => { const { provider, document } = setup('hoverinfo.svelte'); assert.deepStrictEqual(await provider.doHover(document, Position.create(9, 10)), { - contents: - '```typescript\nconst withJsDocTag: true\n```\n---\n\n\n*@author* — foo', + contents: '```typescript\nconst withJsDocTag: true\n```\n---\n\n\n*@author* — foo', range: { start: { character: 10, diff --git a/packages/language-server/test/plugins/typescript/features/SemanticTokensProvider.test.ts b/packages/language-server/test/plugins/typescript/features/SemanticTokensProvider.test.ts index 205236fac..934f82fda 100644 --- a/packages/language-server/test/plugins/typescript/features/SemanticTokensProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/SemanticTokensProvider.test.ts @@ -169,7 +169,7 @@ describe('SemanticTokensProvider', () => { let index = 0; while (index < tokens.length) { - result.push(tokens.splice(index, index += 5)); + result.push(tokens.splice(index, (index += 5))); } return result; diff --git a/packages/language-server/test/plugins/typescript/features/SignatureHelpProvider.test.ts b/packages/language-server/test/plugins/typescript/features/SignatureHelpProvider.test.ts index 7c9b55aa7..1d796400f 100644 --- a/packages/language-server/test/plugins/typescript/features/SignatureHelpProvider.test.ts +++ b/packages/language-server/test/plugins/typescript/features/SignatureHelpProvider.test.ts @@ -15,12 +15,7 @@ describe('SignatureHelpProvider', () => { const docManager = new DocumentManager( (textDocument) => new Document(textDocument.uri, textDocument.text) ); - const filePath = path.join( - testDir, - 'testfiles', - 'signature-help', - 'signature-help.svelte' - ); + const filePath = path.join(testDir, 'testfiles', 'signature-help', 'signature-help.svelte'); const lsAndTsDocResolver = new LSAndTSDocResolver( docManager, [pathToUrl(testDir)], @@ -39,7 +34,7 @@ describe('SignatureHelpProvider', () => { const result = await provider.getSignatureHelp(document, Position.create(3, 8), undefined); - assert.deepStrictEqual(result, { + assert.deepStrictEqual(result, { signatures: [ { label: 'foo(): boolean', @@ -57,7 +52,7 @@ describe('SignatureHelpProvider', () => { const result = await provider.getSignatureHelp(document, Position.create(4, 12), undefined); - assert.deepStrictEqual(result, { + assert.deepStrictEqual(result, { signatures: [ { label: 'abc(a: number, b: number): string', @@ -94,7 +89,10 @@ describe('SignatureHelpProvider', () => { const { provider, document } = setup(); const result = await provider.getSignatureHelp( - document, Position.create(18, 18), undefined); + document, + Position.create(18, 18), + undefined + ); assert.equal(result, null); }); diff --git a/packages/language-server/test/plugins/typescript/features/getDirectiveCommentCompletions.test.ts b/packages/language-server/test/plugins/typescript/features/getDirectiveCommentCompletions.test.ts index 486f1c332..a2196df42 100644 --- a/packages/language-server/test/plugins/typescript/features/getDirectiveCommentCompletions.test.ts +++ b/packages/language-server/test/plugins/typescript/features/getDirectiveCommentCompletions.test.ts @@ -3,11 +3,7 @@ import ts from 'typescript'; import assert from 'assert'; import { Document } from '../../../../src/lib/documents'; import { pathToUrl } from '../../../../src/utils'; -import { - Position, - CompletionContext, - CompletionTriggerKind -} from 'vscode-languageserver'; +import { Position, CompletionContext, CompletionTriggerKind } from 'vscode-languageserver'; import { getDirectiveCommentCompletions } from '../../../../src/plugins/typescript/features/getDirectiveCommentCompletions'; describe('can get typescript directive comment completions', () => { @@ -30,89 +26,86 @@ describe('can get typescript directive comment completions', () => { function testForScript(position: Position) { const result = setup(position); - assert.deepStrictEqual( - result, - { - isIncomplete: false, - items: [ - { - detail: - 'Enables semantic checking in a JavaScript file. Must be at the top of a file.', - kind: 15, - label: '@ts-check', - textEdit: { - newText: '@ts-check', - range: { - end: { - character: 11, - line: position.line - }, - start: { - character: 2, - line: position.line - } + assert.deepStrictEqual(result, { + isIncomplete: false, + items: [ + { + detail: + 'Enables semantic checking in a JavaScript file. Must be at the top of a file.', + kind: 15, + label: '@ts-check', + textEdit: { + newText: '@ts-check', + range: { + end: { + character: 11, + line: position.line + }, + start: { + character: 2, + line: position.line } } - }, - { - detail: - 'Disables semantic checking in a JavaScript file. Must be at the top of a file.', - kind: 15, - label: '@ts-nocheck', - textEdit: { - newText: '@ts-nocheck', - range: { - end: { - character: 13, - line: position.line - }, - start: { - character: 2, - line: position.line - } + } + }, + { + detail: + 'Disables semantic checking in a JavaScript file. Must be at the top of a file.', + kind: 15, + label: '@ts-nocheck', + textEdit: { + newText: '@ts-nocheck', + range: { + end: { + character: 13, + line: position.line + }, + start: { + character: 2, + line: position.line } } - }, - { - detail: 'Suppresses @ts-check errors on the next line of a file.', - kind: 15, - label: '@ts-ignore', - textEdit: { - newText: '@ts-ignore', - range: { - end: { - character: 12, - line: position.line - }, - start: { - character: 2, - line: position.line - } + } + }, + { + detail: 'Suppresses @ts-check errors on the next line of a file.', + kind: 15, + label: '@ts-ignore', + textEdit: { + newText: '@ts-ignore', + range: { + end: { + character: 12, + line: position.line + }, + start: { + character: 2, + line: position.line } } - }, - { - detail: - 'Suppresses @ts-check errors on the next line of a file, expecting at least one to exist.', - kind: 15, - label: '@ts-expect-error', - textEdit: { - newText: '@ts-expect-error', - range: { - end: { - character: 18, - line: position.line - }, - start: { - character: 2, - line: position.line - } + } + }, + { + detail: + 'Suppresses @ts-check errors on the next line of a file, expecting at least one to exist.', + kind: 15, + label: '@ts-expect-error', + textEdit: { + newText: '@ts-expect-error', + range: { + end: { + character: 18, + line: position.line + }, + start: { + character: 2, + line: position.line } } } - ] - } - ); + } + ] + }); } it('provides in instance scripts', () => { @@ -123,7 +116,7 @@ describe('can get typescript directive comment completions', () => { testForScript(Position.create(5, 3)); }); - it('don\'t provide in markup', () => { + it("don't provide in markup", () => { const result = setup(Position.create(7, 3)); assert.deepStrictEqual(result, null); }); diff --git a/packages/language-server/test/plugins/typescript/testfiles/preferences/tsconfig.json b/packages/language-server/test/plugins/typescript/testfiles/preferences/tsconfig.json index 599143b86..24d965d56 100644 --- a/packages/language-server/test/plugins/typescript/testfiles/preferences/tsconfig.json +++ b/packages/language-server/test/plugins/typescript/testfiles/preferences/tsconfig.json @@ -10,6 +10,6 @@ "baseUrl": ".", "paths": { "~/*": ["./*"] - }, + } } } diff --git a/packages/language-server/wallaby.js b/packages/language-server/wallaby.js index 3f2d12a5f..afe061c53 100644 --- a/packages/language-server/wallaby.js +++ b/packages/language-server/wallaby.js @@ -1,4 +1,4 @@ -module.exports = function(_w) { +module.exports = function (_w) { return { files: ['src/**/*.ts'], tests: ['test/**/*.ts'], diff --git a/packages/svelte-vscode/CHANGELOG.md b/packages/svelte-vscode/CHANGELOG.md index 570dd3455..c8c4cda62 100644 --- a/packages/svelte-vscode/CHANGELOG.md +++ b/packages/svelte-vscode/CHANGELOG.md @@ -1,3 +1,3 @@ # Changelog -See https://github.com/sveltejs/language-tools/releases +See https://github.com/sveltejs/language-tools/releases diff --git a/packages/svelte-vscode/package.json b/packages/svelte-vscode/package.json index cfc9b80fd..c30d29f62 100644 --- a/packages/svelte-vscode/package.json +++ b/packages/svelte-vscode/package.json @@ -131,10 +131,10 @@ "description": "Enable rename functionality for JS/TS variables inside Svelte files" }, "svelte.plugin.typescript.semanticTokens.enable": { - "type": "boolean", - "default": true, - "title": "TypeScript: Semantic Tokens", - "description": "Enable semantic tokens (semantic highlight) for TypeScript. Doesn't apply to JavaScript" + "type": "boolean", + "default": true, + "title": "TypeScript: Semantic Tokens", + "description": "Enable semantic tokens (semantic highlight) for TypeScript. Doesn't apply to JavaScript" }, "svelte.plugin.css.enable": { "type": "boolean", diff --git a/packages/svelte-vscode/src/html/autoClose.ts b/packages/svelte-vscode/src/html/autoClose.ts index 948f6d57c..1dc71b2b3 100644 --- a/packages/svelte-vscode/src/html/autoClose.ts +++ b/packages/svelte-vscode/src/html/autoClose.ts @@ -6,14 +6,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import { - window, - workspace, - Disposable, - TextDocument, - Position, - SnippetString -} from 'vscode'; +import { window, workspace, Disposable, TextDocument, Position, SnippetString } from 'vscode'; import { TextDocumentContentChangeEvent } from 'vscode-languageserver-protocol'; @@ -24,7 +17,7 @@ export function activateTagClosing( ): Disposable { const disposables: Disposable[] = []; workspace.onDidChangeTextDocument( - event => onDidChangeTextDocument(event.document, event.contentChanges), + (event) => onDidChangeTextDocument(event.document, event.contentChanges), null, disposables ); @@ -67,17 +60,23 @@ export function activateTagClosing( } const lastChange = changes[changes.length - 1]; const lastCharacter = lastChange.text[lastChange.text.length - 1]; - if ('range' in lastChange && (lastChange.rangeLength ?? 0) > 0 || (lastCharacter !== '>' && lastCharacter !== '/')) { + if ( + ('range' in lastChange && (lastChange.rangeLength ?? 0) > 0) || + (lastCharacter !== '>' && lastCharacter !== '/') + ) { return; } - const rangeStart = 'range' in lastChange ? lastChange.range.start : new Position(0, document.getText().length); + const rangeStart = + 'range' in lastChange + ? lastChange.range.start + : new Position(0, document.getText().length); const version = document.version; timeout = setTimeout(() => { const position = new Position( rangeStart.line, rangeStart.character + lastChange.text.length ); - tagProvider(document, position).then(text => { + tagProvider(document, position).then((text) => { if (text && isEnabled) { const activeEditor = window.activeTextEditor; if (activeEditor) { @@ -86,11 +85,11 @@ export function activateTagClosing( const selections = activeEditor.selections; if ( selections.length && - selections.some(s => s.active.isEqual(position)) + selections.some((s) => s.active.isEqual(position)) ) { activeEditor.insertSnippet( new SnippetString(text), - selections.map(s => s.active) + selections.map((s) => s.active) ); } else { activeEditor.insertSnippet(new SnippetString(text), position); diff --git a/packages/svelte-vscode/src/html/htmlEmptyTagsShared.ts b/packages/svelte-vscode/src/html/htmlEmptyTagsShared.ts index 9e4a048eb..99e6df7f7 100644 --- a/packages/svelte-vscode/src/html/htmlEmptyTagsShared.ts +++ b/packages/svelte-vscode/src/html/htmlEmptyTagsShared.ts @@ -23,4 +23,3 @@ export const EMPTY_ELEMENTS: string[] = [ 'track', 'wbr' ]; - diff --git a/packages/svelte-vscode/syntaxes/pug-svelte-dotblock.json b/packages/svelte-vscode/syntaxes/pug-svelte-dotblock.json index 74d0d56c5..2f141a508 100644 --- a/packages/svelte-vscode/syntaxes/pug-svelte-dotblock.json +++ b/packages/svelte-vscode/syntaxes/pug-svelte-dotblock.json @@ -1,55 +1,55 @@ { - "scopeName": "svelte.pug.dotblock", - "fileTypes": [], - "injectionSelector": "L:text.block.pug -meta.embedded.ts", - "patterns": [ - { - "include": "#interp-object-literal" - }, - { - "include": "#interp" - } - ], - "repository": { - "interp-object-literal": { - "contentName": "meta.interpolation meta.embedded.ts", - "begin": "(?![!$#]){\\s*?(?={)", - "beginCaptures": { - "0": { - "name": "punctuation.section.interpolation.begin" - } - }, - "end": "(?<=})\\s*?}", - "endCaptures": { - "0": { - "name": "punctuation.section.interpolation.end" - } - }, - "patterns": [ + "scopeName": "svelte.pug.dotblock", + "fileTypes": [], + "injectionSelector": "L:text.block.pug -meta.embedded.ts", + "patterns": [ { - "include": "source.ts#object-literal" - } - ] - }, - "interp": { - "contentName": "meta.interpolation meta.embedded.ts", - "begin": "(?![!$#]){", - "beginCaptures": { - "0": { - "name": "punctuation.section.interpolation.begin" - } - }, - "end": "}", - "endCaptures": { - "0": { - "name": "punctuation.section.interpolation.end" - } - }, - "patterns": [ + "include": "#interp-object-literal" + }, { - "include": "source.ts" + "include": "#interp" + } + ], + "repository": { + "interp-object-literal": { + "contentName": "meta.interpolation meta.embedded.ts", + "begin": "(?![!$#]){\\s*?(?={)", + "beginCaptures": { + "0": { + "name": "punctuation.section.interpolation.begin" + } + }, + "end": "(?<=})\\s*?}", + "endCaptures": { + "0": { + "name": "punctuation.section.interpolation.end" + } + }, + "patterns": [ + { + "include": "source.ts#object-literal" + } + ] + }, + "interp": { + "contentName": "meta.interpolation meta.embedded.ts", + "begin": "(?![!$#]){", + "beginCaptures": { + "0": { + "name": "punctuation.section.interpolation.begin" + } + }, + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.section.interpolation.end" + } + }, + "patterns": [ + { + "include": "source.ts" + } + ] } - ] } - } -} \ No newline at end of file +} diff --git a/packages/svelte-vscode/syntaxes/pug-svelte-tags.json b/packages/svelte-vscode/syntaxes/pug-svelte-tags.json index 6fe465f2f..fdab54950 100644 --- a/packages/svelte-vscode/syntaxes/pug-svelte-tags.json +++ b/packages/svelte-vscode/syntaxes/pug-svelte-tags.json @@ -1,201 +1,201 @@ { - "scopeName": "svelte.pug.tags", - "fileTypes": [], - "injectionSelector": "L:text.pug meta.tag.other -meta.embedded.ts", - "patterns": [ - { - "include": "#interp-object-literal" - }, - { - "include": "#interp" - }, - { - "include": "#attr-function" - }, - { - "include": "#attr-interp" - }, - { - "include": "#attr-interp-invalid-quotes" - }, - { - "include": "#attr-interp-invalid-noquotes" - }, - { - "include": "#attr-event" - }, - { - "include": "#attr-variable" - } - ], - "repository": { - "interp-object-literal": { - "contentName": "meta.interpolation meta.embedded.ts", - "begin": "(?![!$#]){\\s*?(?={)", - "beginCaptures": { - "0": { - "name": "punctuation.section.interpolation.begin" - } - }, - "end": "(?<=})\\s*?}", - "endCaptures": { - "0": { - "name": "punctuation.section.interpolation.end" - } - }, - "patterns": [ + "scopeName": "svelte.pug.tags", + "fileTypes": [], + "injectionSelector": "L:text.pug meta.tag.other -meta.embedded.ts", + "patterns": [ { - "include": "source.ts#object-literal" - } - ] - }, - "interp": { - "contentName": "meta.interpolation meta.embedded.ts", - "begin": "(?![!$#]){", - "beginCaptures": { - "0": { - "name": "punctuation.section.interpolation.begin" - } - }, - "end": "}", - "endCaptures": { - "0": { - "name": "punctuation.section.interpolation.end" - } - }, - "patterns": [ + "include": "#interp-object-literal" + }, { - "include": "source.ts" - } - ] - }, - "attr-interp": { - "match": "\\b(?<=[\\w$\\-_]*)\\s*?(!=|=)\\s*?([`'\"])((?![$!#]){.*})(\\k<2>)", - "captures": { - "1": { - "patterns": [ - { - "match": "=", - "name": "invalid.illegal" - }, - { - "match": "!=", - "name": "keyword.operator.assignment" - } - ] + "include": "#interp" }, - "2": { - "name": "punctuation.section.interpolation.begin" + { + "include": "#attr-function" }, - "3": { - "patterns": [ - { - "include": "#interp" - } - ] + { + "include": "#attr-interp" }, - "4": { - "name": "punctuation.section.interpolation.begin" - } - } - }, - "attr-interp-invalid-quotes": { - "match": "\\b(?<=[\\w$\\-_]*)\\s*?(!=|=)\\s*?([`'\"])((?![$!#]){.*})(?!\\k<2>)", - "captures": { - "1": { - "patterns": [ - { - "match": "=", - "name": "invalid.illegal" - }, - { - "match": "!=", - "name": "keyword.operator.assignment" - } - ] + { + "include": "#attr-interp-invalid-quotes" }, - "2": { - "name": "punctuation.section.interpolation.begin" + { + "include": "#attr-interp-invalid-noquotes" }, - "3": { - "name": "invalid.illegal" + { + "include": "#attr-event" }, - "4": { - "name": "invalid.illegal" + { + "include": "#attr-variable" } - } - }, - "attr-interp-invalid-noquotes": { - "match": "\\b(?<=[\\w$\\-_]*)\\s*?(!=|=)\\s*?(?![`'\"])((?![$!#]){.*})(?![`'\"])", - "captures": { - "1": { - "patterns": [ - { - "match": "=", - "name": "invalid.illegal" + ], + "repository": { + "interp-object-literal": { + "contentName": "meta.interpolation meta.embedded.ts", + "begin": "(?![!$#]){\\s*?(?={)", + "beginCaptures": { + "0": { + "name": "punctuation.section.interpolation.begin" + } }, - { - "match": "!=", - "name": "keyword.operator.assignment" - } - ] + "end": "(?<=})\\s*?}", + "endCaptures": { + "0": { + "name": "punctuation.section.interpolation.end" + } + }, + "patterns": [ + { + "include": "source.ts#object-literal" + } + ] }, - "2": { - "name": "invalid.illegal" + "interp": { + "contentName": "meta.interpolation meta.embedded.ts", + "begin": "(?![!$#]){", + "beginCaptures": { + "0": { + "name": "punctuation.section.interpolation.begin" + } + }, + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.section.interpolation.end" + } + }, + "patterns": [ + { + "include": "source.ts" + } + ] }, - "3": { - "patterns": [ - { - "include": "#interp" + "attr-interp": { + "match": "\\b(?<=[\\w$\\-_]*)\\s*?(!=|=)\\s*?([`'\"])((?![$!#]){.*})(\\k<2>)", + "captures": { + "1": { + "patterns": [ + { + "match": "=", + "name": "invalid.illegal" + }, + { + "match": "!=", + "name": "keyword.operator.assignment" + } + ] + }, + "2": { + "name": "punctuation.section.interpolation.begin" + }, + "3": { + "patterns": [ + { + "include": "#interp" + } + ] + }, + "4": { + "name": "punctuation.section.interpolation.begin" + } } - ] - }, - "4": { - "name": "invalid.illegal" - } - } - }, - "attr-function": { - "match": "\\b(use|transition|in|out|animate)(:)(\\w+)", - "captures": { - "1": { - "name": "entity.other.attribute-name" }, - "2": { - "name": "keyword.operator.assignment" - }, - "3": { - "name": "variable.function" - } - } - }, - "attr-event": { - "match": "\\b(on)(:)(\\w+)", - "captures": { - "1": { - "name": "entity.other.attribute-name" + "attr-interp-invalid-quotes": { + "match": "\\b(?<=[\\w$\\-_]*)\\s*?(!=|=)\\s*?([`'\"])((?![$!#]){.*})(?!\\k<2>)", + "captures": { + "1": { + "patterns": [ + { + "match": "=", + "name": "invalid.illegal" + }, + { + "match": "!=", + "name": "keyword.operator.assignment" + } + ] + }, + "2": { + "name": "punctuation.section.interpolation.begin" + }, + "3": { + "name": "invalid.illegal" + }, + "4": { + "name": "invalid.illegal" + } + } }, - "2": { - "name": "keyword.operator.assignment" + "attr-interp-invalid-noquotes": { + "match": "\\b(?<=[\\w$\\-_]*)\\s*?(!=|=)\\s*?(?![`'\"])((?![$!#]){.*})(?![`'\"])", + "captures": { + "1": { + "patterns": [ + { + "match": "=", + "name": "invalid.illegal" + }, + { + "match": "!=", + "name": "keyword.operator.assignment" + } + ] + }, + "2": { + "name": "invalid.illegal" + }, + "3": { + "patterns": [ + { + "include": "#interp" + } + ] + }, + "4": { + "name": "invalid.illegal" + } + } }, - "3": { - "name": "entity.name.type" - } - } - }, - "attr-variable": { - "match": "\\b(bind|class|let)(:)(\\w+)", - "captures": { - "1": { - "name": "entity.other.attribute-name" + "attr-function": { + "match": "\\b(use|transition|in|out|animate)(:)(\\w+)", + "captures": { + "1": { + "name": "entity.other.attribute-name" + }, + "2": { + "name": "keyword.operator.assignment" + }, + "3": { + "name": "variable.function" + } + } }, - "2": { - "name": "keyword.operator.assignment" + "attr-event": { + "match": "\\b(on)(:)(\\w+)", + "captures": { + "1": { + "name": "entity.other.attribute-name" + }, + "2": { + "name": "keyword.operator.assignment" + }, + "3": { + "name": "entity.name.type" + } + } }, - "3": { - "name": "variable.parameter" + "attr-variable": { + "match": "\\b(bind|class|let)(:)(\\w+)", + "captures": { + "1": { + "name": "entity.other.attribute-name" + }, + "2": { + "name": "keyword.operator.assignment" + }, + "3": { + "name": "variable.parameter" + } + } } - } } - } -} \ No newline at end of file +} diff --git a/packages/svelte-vscode/syntaxes/pug-svelte.json b/packages/svelte-vscode/syntaxes/pug-svelte.json index 0a34fd74a..430ce7e6b 100644 --- a/packages/svelte-vscode/syntaxes/pug-svelte.json +++ b/packages/svelte-vscode/syntaxes/pug-svelte.json @@ -1,293 +1,293 @@ { - "scopeName": "svelte.pug", - "fileTypes": [], - "injectionSelector": "L:text.pug -meta.embedded.ts -meta.tag.other -text.block.pug, L:inline.pug -meta.embedded.ts -meta.tag.other", - "patterns": [ - { - "include": "#interp-object-literal" - }, - { - "include": "#interp" - }, - { - "include": "#tag-component" - }, - { - "include": "#tag-component-no-params" - }, - { - "include": "#mixin-svelte" - }, - { - "include": "#mixin-else" - } - ], - "repository": { - "interp-object-literal": { - "contentName": "meta.interpolation meta.embedded.ts", - "begin": "(?![!$#]){\\s*?(?={)", - "beginCaptures": { - "0": { - "name": "punctuation.section.interpolation.begin" - } - }, - "end": "(?<=})\\s*?}", - "endCaptures": { - "0": { - "name": "punctuation.section.interpolation.end" - } - }, - "patterns": [ + "scopeName": "svelte.pug", + "fileTypes": [], + "injectionSelector": "L:text.pug -meta.embedded.ts -meta.tag.other -text.block.pug, L:inline.pug -meta.embedded.ts -meta.tag.other", + "patterns": [ { - "include": "source.ts#object-literal" - } - ] - }, - "interp": { - "contentName": "meta.interpolation meta.embedded.ts", - "begin": "(?![!$#]){", - "beginCaptures": { - "0": { - "name": "punctuation.section.interpolation.begin" - } - }, - "end": "}", - "endCaptures": { - "0": { - "name": "punctuation.section.interpolation.end" - } - }, - "patterns": [ + "include": "#interp-object-literal" + }, { - "include": "source.ts" - } - ] - }, - "tag-component": { - "name": "meta.tag.svelte", - "begin": "(?<=^\\s*?|#\\[\\s*?|:\\s+?)([A-Z][a-zA-Z0-9_]*)\\s*?(?=\\()", - "beginCaptures": { - "0": { - "name": "support.class.component.svelte" - } - }, - "end": "(?<=\\))", - "endCaptures": { - "0": { - "name": "constant.name.attribute.tag" - } - }, - "patterns": [ + "include": "#interp" + }, { - "include": "text.pug#tag_attributes" - } - ] - }, - "tag-component-no-params": { - "name": "meta.tag.svelte", - "match": "(?<=^\\s*?|#\\[\\s*?|:\\s+?)([A-Z][a-zA-Z0-9_]*)", - "captures": { - "0": { - "name": "support.class.component.svelte" - } - } - }, - "mixin-svelte": { - "match": "(?<=^\\s*?|#\\[\\s*?|:\\s+?)(\\+)(debug|if|elseif|then|catch|each|await|html|key)\\s*?(\\()\\s*?([`'\"])(.*?)(\\k<4>)\\s*?(\\))", - "captures": { - "1": { - "name": "punctuation.definition.keyword" + "include": "#tag-component" + }, + { + "include": "#tag-component-no-params" }, - "2": { - "patterns": [ - { - "match": "debug", - "name": "keyword.other.debugger" + { + "include": "#mixin-svelte" + }, + { + "include": "#mixin-else" + } + ], + "repository": { + "interp-object-literal": { + "contentName": "meta.interpolation meta.embedded.ts", + "begin": "(?![!$#]){\\s*?(?={)", + "beginCaptures": { + "0": { + "name": "punctuation.section.interpolation.begin" + } }, - { - "match": "if|elseif", - "name": "keyword.control.conditional" + "end": "(?<=})\\s*?}", + "endCaptures": { + "0": { + "name": "punctuation.section.interpolation.end" + } }, - { - "match": "then|catch|await", - "name": "keyword.control.flow" + "patterns": [ + { + "include": "source.ts#object-literal" + } + ] + }, + "interp": { + "contentName": "meta.interpolation meta.embedded.ts", + "begin": "(?![!$#]){", + "beginCaptures": { + "0": { + "name": "punctuation.section.interpolation.begin" + } }, - { - "match": "each", - "name": "keyword.control" + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.section.interpolation.end" + } }, - { - "match": "html|key", - "name": "support.function" - } - ] + "patterns": [ + { + "include": "source.ts" + } + ] }, - "3": { - "name": "meta.brace.round" + "tag-component": { + "name": "meta.tag.svelte", + "begin": "(?<=^\\s*?|#\\[\\s*?|:\\s+?)([A-Z][a-zA-Z0-9_]*)\\s*?(?=\\()", + "beginCaptures": { + "0": { + "name": "support.class.component.svelte" + } + }, + "end": "(?<=\\))", + "endCaptures": { + "0": { + "name": "constant.name.attribute.tag" + } + }, + "patterns": [ + { + "include": "text.pug#tag_attributes" + } + ] }, - "4": { - "name": "punctuation.definition.generic.begin" + "tag-component-no-params": { + "name": "meta.tag.svelte", + "match": "(?<=^\\s*?|#\\[\\s*?|:\\s+?)([A-Z][a-zA-Z0-9_]*)", + "captures": { + "0": { + "name": "support.class.component.svelte" + } + } }, - "5": { - "patterns": [ - { - "match": "(?<=each\\s*?\\(\\s*?')(.*)\\s+?(as\\s+?(.*?)(\\s*?,\\s*?)(.*?|)(\\s+?\\(.*\\)|)$)", - "captures": { + "mixin-svelte": { + "match": "(?<=^\\s*?|#\\[\\s*?|:\\s+?)(\\+)(debug|if|elseif|then|catch|each|await|html|key)\\s*?(\\()\\s*?([`'\"])(.*?)(\\k<4>)\\s*?(\\))", + "captures": { "1": { - "name": "meta.embedded.ts", - "patterns": [ - { - "include": "source.ts" - } - ] + "name": "punctuation.definition.keyword" }, "2": { - "name": "keyword.control.as" + "patterns": [ + { + "match": "debug", + "name": "keyword.other.debugger" + }, + { + "match": "if|elseif", + "name": "keyword.control.conditional" + }, + { + "match": "then|catch|await", + "name": "keyword.control.flow" + }, + { + "match": "each", + "name": "keyword.control" + }, + { + "match": "html|key", + "name": "support.function" + } + ] }, "3": { - "name": "meta.embedded.t", - "patterns": [ - { - "include": "source.ts" - } - ] + "name": "meta.brace.round" }, "4": { - "name": "punctuation.separator" + "name": "punctuation.definition.generic.begin" }, "5": { - "name": "meta.embedded.t", - "patterns": [ - { - "include": "source.ts" - } - ] - }, - "6": { - "patterns": [ - { - "match": "(\\()(.*)(\\))", - "captures": { - "1": { - "name": "meta.brace.round" + "patterns": [ + { + "match": "(?<=each\\s*?\\(\\s*?')(.*)\\s+?(as\\s+?(.*?)(\\s*?,\\s*?)(.*?|)(\\s+?\\(.*\\)|)$)", + "captures": { + "1": { + "name": "meta.embedded.ts", + "patterns": [ + { + "include": "source.ts" + } + ] + }, + "2": { + "name": "keyword.control.as" + }, + "3": { + "name": "meta.embedded.t", + "patterns": [ + { + "include": "source.ts" + } + ] + }, + "4": { + "name": "punctuation.separator" + }, + "5": { + "name": "meta.embedded.t", + "patterns": [ + { + "include": "source.ts" + } + ] + }, + "6": { + "patterns": [ + { + "match": "(\\()(.*)(\\))", + "captures": { + "1": { + "name": "meta.brace.round" + }, + "2": { + "name": "variable" + }, + "3": { + "name": "meta.brace.round" + } + } + } + ] + } + } }, - "2": { - "name": "variable" + { + "match": "(?<=each\\s*?\\(\\s*?')(.*)\\s+?(as\\s+?(.*?)(\\s+?\\(.*\\)|)$)", + "captures": { + "1": { + "name": "meta.embedded.ts", + "patterns": [ + { + "include": "source.ts" + } + ] + }, + "2": { + "name": "keyword.control.as" + }, + "3": { + "name": "meta.embedded.t", + "patterns": [ + { + "include": "source.ts" + } + ] + }, + "4": { + "patterns": [ + { + "match": "(\\()(.*)(\\))", + "captures": { + "1": { + "name": "meta.brace.round" + }, + "2": { + "name": "variable" + }, + "3": { + "name": "meta.brace.round" + } + } + } + ] + } + } }, - "3": { - "name": "meta.brace.round" - } - } - } - ] - } - } - }, - { - "match": "(?<=each\\s*?\\(\\s*?')(.*)\\s+?(as\\s+?(.*?)(\\s+?\\(.*\\)|)$)", - "captures": { - "1": { - "name": "meta.embedded.ts", - "patterns": [ - { - "include": "source.ts" - } - ] - }, - "2": { - "name": "keyword.control.as" - }, - "3": { - "name": "meta.embedded.t", - "patterns": [ - { - "include": "source.ts" - } - ] - }, - "4": { - "patterns": [ - { - "match": "(\\()(.*)(\\))", - "captures": { - "1": { - "name": "meta.brace.round" + { + "match": "(?<=await\\s*?\\(\\s*?')(.*)\\s+?(then(.*)$)", + "captures": { + "1": { + "name": "meta.embedded.ts", + "patterns": [ + { + "include": "source.ts" + } + ] + }, + "2": { + "name": "keyword.control.flow" + }, + "3": { + "name": "variable" + } + } }, - "2": { - "name": "variable" + { + "match": "(?<=debug\\s*?\\(\\s*?')(\\w+?)(,|$)", + "captures": { + "1": { + "name": "variable" + }, + "2": { + "name": "punctuation.separator" + } + } }, - "3": { - "name": "meta.brace.round" + { + "match": "(.*)$", + "captures": { + "0": { + "name": "meta.embedded.ts", + "patterns": [ + { + "include": "source.ts" + } + ] + } + } } - } - } - ] - } - } - }, - { - "match": "(?<=await\\s*?\\(\\s*?')(.*)\\s+?(then(.*)$)", - "captures": { - "1": { - "name": "meta.embedded.ts", - "patterns": [ - { - "include": "source.ts" - } - ] + ] }, - "2": { - "name": "keyword.control.flow" + "6": { + "name": "punctuation.definition.generic.end" }, - "3": { - "name": "variable" + "7": { + "name": "meta.brace.round" } - } - }, - { - "match": "(?<=debug\\s*?\\(\\s*?')(\\w+?)(,|$)", - "captures": { + } + }, + "mixin-else": { + "match": "(?<=^\\s*?|#\\[\\s*?|:\\s+?)(\\+)(else)", + "captures": { "1": { - "name": "variable" + "name": "punctuation.definition.keyword" }, "2": { - "name": "punctuation.separator" - } - } - }, - { - "match": "(.*)$", - "captures": { - "0": { - "name": "meta.embedded.ts", - "patterns": [ - { - "include": "source.ts" - } - ] + "name": "keyword.control.conditional" } - } } - ] - }, - "6": { - "name": "punctuation.definition.generic.end" - }, - "7": { - "name": "meta.brace.round" - } - } - }, - "mixin-else": { - "match": "(?<=^\\s*?|#\\[\\s*?|:\\s+?)(\\+)(else)", - "captures": { - "1": { - "name": "punctuation.definition.keyword" - }, - "2": { - "name": "keyword.control.conditional" } - } } - } -} \ No newline at end of file +} diff --git a/packages/svelte2tsx/README.md b/packages/svelte2tsx/README.md index a491547fb..f15f4a000 100644 --- a/packages/svelte2tsx/README.md +++ b/packages/svelte2tsx/README.md @@ -18,10 +18,12 @@ For example Input.svelte ```svelte -

hello {world}

+ +

hello {world}

+ ``` will produce this ugly but type checkable TSX @@ -37,7 +39,7 @@ function render() { } export default class _World_ extends createSvelte2TsxComponent( - __sveltets_partial(__sveltets_with_any_event(render)), + __sveltets_partial(__sveltets_with_any_event(render)) ) {} ``` diff --git a/packages/svelte2tsx/src/htmlxtojsx/nodes/event-handler.ts b/packages/svelte2tsx/src/htmlxtojsx/nodes/event-handler.ts index 704033322..7c6de7958 100644 --- a/packages/svelte2tsx/src/htmlxtojsx/nodes/event-handler.ts +++ b/packages/svelte2tsx/src/htmlxtojsx/nodes/event-handler.ts @@ -37,9 +37,9 @@ export function handleEventHandler( //for handler assignment, we change it to call to our __sveltets_ensureFunction str.appendRight(attr.start, `{__sveltets_instanceOf(${getTypeForComponent(parent)}).$`); const eventNameIndex = htmlx.indexOf(':', attr.start) + 1; - str.overwrite(htmlx.indexOf(on, attr.start) + on.length, eventNameIndex, '(\''); + str.overwrite(htmlx.indexOf(on, attr.start) + on.length, eventNameIndex, "('"); const eventEnd = htmlx.lastIndexOf('=', attr.expression.start); - str.overwrite(eventEnd, attr.expression.start, '\', '); + str.overwrite(eventEnd, attr.expression.start, "', "); str.overwrite(attr.expression.end, attr.end, ')}'); str.move(attr.start, attr.end, parent.end); } else { diff --git a/packages/svelte2tsx/src/svelte2tsx/nodes/handleTypeAssertion.ts b/packages/svelte2tsx/src/svelte2tsx/nodes/handleTypeAssertion.ts index bf7c68e11..3b43f9faa 100644 --- a/packages/svelte2tsx/src/svelte2tsx/nodes/handleTypeAssertion.ts +++ b/packages/svelte2tsx/src/svelte2tsx/nodes/handleTypeAssertion.ts @@ -24,4 +24,3 @@ export function handleTypeAssertion( // remove '>' str.remove(typeEnd, expressionStart); } - diff --git a/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts b/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts index 628c8c9be..ba072ee31 100644 --- a/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts +++ b/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts @@ -279,7 +279,8 @@ export function processInstanceScriptContent( if ( (!ts.isPropertyAccessExpression(parent) || parent.expression == ident) && (!ts.isPropertyAssignment(parent) || parent.initializer == ident) && - !ts.isPropertySignature(parent) && !ts.isPropertyDeclaration(parent) + !ts.isPropertySignature(parent) && + !ts.isPropertyDeclaration(parent) ) { pendingStoreResolutions.push({ node: ident, parent, scope }); } diff --git a/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts b/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts index eaa213b69..79460135c 100644 --- a/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts +++ b/packages/svelte2tsx/src/svelte2tsx/utils/tsAst.ts @@ -134,8 +134,7 @@ export function getLastLeadingDoc(node: ts.Node): string | undefined { if (comment) { let commentText = nodeText.substring(comment.pos, comment.end); - const typedefTags = ts.getAllJSDocTagsOfKind( - node, ts.SyntaxKind.JSDocTypedefTag); + const typedefTags = ts.getAllJSDocTagsOfKind(node, ts.SyntaxKind.JSDocTypedefTag); typedefTags .filter((tag) => tag.pos >= comment.pos) .map((tag) => nodeText.substring(tag.pos, tag.end)) diff --git a/packages/svelte2tsx/src/utils/svelteAst.ts b/packages/svelte2tsx/src/utils/svelteAst.ts index 7c24ae777..883c4e817 100644 --- a/packages/svelte2tsx/src/utils/svelteAst.ts +++ b/packages/svelte2tsx/src/utils/svelteAst.ts @@ -1,9 +1,5 @@ import { Node } from 'estree-walker'; -import { - SvelteIdentifier, - SvelteArrayPattern, - SvelteObjectPattern -} from '../interfaces'; +import { SvelteIdentifier, SvelteArrayPattern, SvelteObjectPattern } from '../interfaces'; export function isMember(parent: Node, prop: string) { return parent.type == 'MemberExpression' && prop == 'property'; @@ -19,9 +15,7 @@ export function isObjectValue(parent: Node, prop: string) { export function isObjectValueShortHand(property: Node) { const { value, key } = property; - return ( - value && isIdentifier(value) && key.start === value.start && key.end == value.end - ); + return value && isIdentifier(value) && key.start === value.start && key.end == value.end; } export function isText(node: Node) { diff --git a/packages/svelte2tsx/test/sourcemaps/index.js b/packages/svelte2tsx/test/sourcemaps/index.js index f96152382..0d45d13d6 100644 --- a/packages/svelte2tsx/test/sourcemaps/index.js +++ b/packages/svelte2tsx/test/sourcemaps/index.js @@ -1,165 +1,178 @@ -let svelte2tsx = require('../build/index') -let converter = require('../build/htmlxtojsx') -let fs = require('fs') -let assert = require('assert') -let sm = require('source-map') - - +let svelte2tsx = require('../build/index'); +let converter = require('../build/htmlxtojsx'); +let fs = require('fs'); +let assert = require('assert'); +let sm = require('source-map'); describe('sourcemap', () => { - /** - * - * @param {string} input - * - * @returns { {source: string, locations: Map } - */ - function extractLocations(input) { - let lines = input.split("\n") - let line - let source_line = 0; - let source = [] - let locations = new Map() - while (lines.length) { - line = lines.shift() - //are we a range line, we test to see if it starts with whitespace followed by a digit - if (/^\s*[\d=]+[\s\d=]*$/.test(line)) { - //create the ranges - let currentId = null - let offset = 0 - let offsets = [] - let start = 0 - const endSpan = () => { - if (offsets.length) { - locations.set(currentId, { line: source_line, start: start, offsets:offsets }); - } - offset = 0 - offsets = [] - } - - for (let char = 0; char < line.length; char++) { - let c = line[char] - let isDigit = /\d/.test(c), isEquals = /=/.test(c) - if (isDigit) { - endSpan() - currentId = c - start = char + 1; - } - if (isEquals || isDigit) { - offsets.push(offset) - offset++; - } else { - endSpan() - } - } - endSpan(); - } else { - //we are a source line - source.push(line) - source_line++; - } - } - - return { source: source.join("\n") , locations } - } - - - fs.readdirSync(`${__dirname}`).forEach(dir => { - if (dir[0] === '.') return; - - if (!dir.endsWith(".html") && !dir.endsWith(".html.solo")) return; - - // add .solo to a sample directory name to only run that test - const solo = /\.solo$/.test(dir); - - if (solo && process.env.CI) { - throw new Error( - `Forgot to remove '.solo' from test parser/samples/${dir}` - ); - } - - let showWhitespace = (str) => { - return str.replace(/\t/g, "\\t").replace(/\n/g,"\\n\n").replace(/\r/g, "\\r") - } - - (solo ? it.only : it)(dir, () => { - const testContent = fs.readFileSync(`${__dirname}/${dir}`, 'utf-8').replace(/\r\n/g, "\n").replace(/\t/g, " "); - - let [inputBlock, expectedBlock] = testContent.split(/\n!Expected.*?\n/) - let input = extractLocations(inputBlock); - let expected = extractLocations(expectedBlock); - - - // seems backwards but we don't have an "input" source map, so we generate one from our expected output - // but assert that the source it generates matches our input source. - //console.log(expected.source) - const { map, code } = dir.endsWith(".htmlx.html") ? converter.htmlx2jsx(expected.source) : svelte2tsx(expected.source); - assert.equal(showWhitespace(code) , showWhitespace(input.source), "Couldn't generate input source map for test"); - - let decoder = new sm.SourceMapConsumer(map); - - for (let [id, span] of input.locations.entries()) { - let expectedSpan = expected.locations.get(id); - - //walk our generated span checking it lines up - let col = span.start - let input_line = span.line - let expected_line = expectedSpan.line - - - assert.ok(input.source); - let error_source = input.source.split("\n")[span.line-1]; - assert.ok(error_source); - let error_map = new Array(error_source.length).fill(" "); - - let actual_result_line, actual_result_source, actual_result - let errorCount = 0; - - for (var off = 0; off < span.offsets.length; off++) { - let input_col = col + off; - let expected_col = expectedSpan.start + span.offsets[off]; - - //originalPositionFor uses 0 base cols and 1 base lines.... - let { line: actual_line, column: decoded_col } = decoder.originalPositionFor({ line: input_line, column: input_col - 1 }) - let actual_col = decoded_col + 1; - - if (!actual_result) { - actual_result_source = expected.source.split("\n")[actual_line-1] - actual_result = new Array(actual_result_source.length).fill(" "); - actual_result_line = actual_line - } - if (actual_line == actual_result_line) { - if (actual_result_line[actual_col - 1] == " ") { - actual_result[actual_col - 1] = "1" - } else { - //track number of characters mapped to result - actual_result[actual_col - 1] = `${Math.min((actual_result[actual_col - 1] << 0) + 1, 9)}` - } - } else { - actual_result = actual_result + "X" - } - - if (actual_col != expected_col || actual_line != expected_line) { - errorCount++; - error_map[input_col-1] = "X" - } else { - error_map[input_col-1] = "=" - } - } - - if (errorCount != 0) { - assert.fail(` + /** + * + * @param {string} input + * + * @returns { {source: string, locations: Map } + */ + function extractLocations(input) { + let lines = input.split('\n'); + let line; + let source_line = 0; + let source = []; + let locations = new Map(); + while (lines.length) { + line = lines.shift(); + //are we a range line, we test to see if it starts with whitespace followed by a digit + if (/^\s*[\d=]+[\s\d=]*$/.test(line)) { + //create the ranges + let currentId = null; + let offset = 0; + let offsets = []; + let start = 0; + const endSpan = () => { + if (offsets.length) { + locations.set(currentId, { + line: source_line, + start: start, + offsets: offsets + }); + } + offset = 0; + offsets = []; + }; + + for (let char = 0; char < line.length; char++) { + let c = line[char]; + let isDigit = /\d/.test(c), + isEquals = /=/.test(c); + if (isDigit) { + endSpan(); + currentId = c; + start = char + 1; + } + if (isEquals || isDigit) { + offsets.push(offset); + offset++; + } else { + endSpan(); + } + } + endSpan(); + } else { + //we are a source line + source.push(line); + source_line++; + } + } + + return { source: source.join('\n'), locations }; + } + + fs.readdirSync(`${__dirname}`).forEach((dir) => { + if (dir[0] === '.') return; + + if (!dir.endsWith('.html') && !dir.endsWith('.html.solo')) return; + + // add .solo to a sample directory name to only run that test + const solo = /\.solo$/.test(dir); + + if (solo && process.env.CI) { + throw new Error(`Forgot to remove '.solo' from test parser/samples/${dir}`); + } + + let showWhitespace = (str) => { + return str.replace(/\t/g, '\\t').replace(/\n/g, '\\n\n').replace(/\r/g, '\\r'); + }; + + (solo ? it.only : it)(dir, () => { + const testContent = fs + .readFileSync(`${__dirname}/${dir}`, 'utf-8') + .replace(/\r\n/g, '\n') + .replace(/\t/g, ' '); + + let [inputBlock, expectedBlock] = testContent.split(/\n!Expected.*?\n/); + let input = extractLocations(inputBlock); + let expected = extractLocations(expectedBlock); + + // seems backwards but we don't have an "input" source map, so we generate one from our expected output + // but assert that the source it generates matches our input source. + //console.log(expected.source) + const { map, code } = dir.endsWith('.htmlx.html') + ? converter.htmlx2jsx(expected.source) + : svelte2tsx(expected.source); + assert.equal( + showWhitespace(code), + showWhitespace(input.source), + "Couldn't generate input source map for test" + ); + + let decoder = new sm.SourceMapConsumer(map); + + for (let [id, span] of input.locations.entries()) { + let expectedSpan = expected.locations.get(id); + + //walk our generated span checking it lines up + let col = span.start; + let input_line = span.line; + let expected_line = expectedSpan.line; + + assert.ok(input.source); + let error_source = input.source.split('\n')[span.line - 1]; + assert.ok(error_source); + let error_map = new Array(error_source.length).fill(' '); + + let actual_result_line, actual_result_source, actual_result; + let errorCount = 0; + + for (var off = 0; off < span.offsets.length; off++) { + let input_col = col + off; + let expected_col = expectedSpan.start + span.offsets[off]; + + //originalPositionFor uses 0 base cols and 1 base lines.... + let { line: actual_line, column: decoded_col } = decoder.originalPositionFor({ + line: input_line, + column: input_col - 1 + }); + let actual_col = decoded_col + 1; + + if (!actual_result) { + actual_result_source = expected.source.split('\n')[actual_line - 1]; + actual_result = new Array(actual_result_source.length).fill(' '); + actual_result_line = actual_line; + } + if (actual_line == actual_result_line) { + if (actual_result_line[actual_col - 1] == ' ') { + actual_result[actual_col - 1] = '1'; + } else { + //track number of characters mapped to result + actual_result[actual_col - 1] = `${Math.min( + (actual_result[actual_col - 1] << 0) + 1, + 9 + )}`; + } + } else { + actual_result = actual_result + 'X'; + } + + if (actual_col != expected_col || actual_line != expected_line) { + errorCount++; + error_map[input_col - 1] = 'X'; + } else { + error_map[input_col - 1] = '='; + } + } + + if (errorCount != 0) { + assert.fail(` Errors on span ${id} Output ${actual_result_source} - ${actual_result.join("").replace(/1/g,"=")} + ${actual_result.join('').replace(/1/g, '=')} Errors ${error_source} - ${error_map.join("")} - `) - } - } - }); - }); -}); \ No newline at end of file + ${error_map.join('')} + `); + } + } + }); + }); +}); diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/component-events-interface-constant/expected.js b/packages/svelte2tsx/test/svelte2tsx/samples/component-events-interface-constant/expected.js index a14e5f924..fe421a93c 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/component-events-interface-constant/expected.js +++ b/packages/svelte2tsx/test/svelte2tsx/samples/component-events-interface-constant/expected.js @@ -1,12 +1,9 @@ -let assert = require('assert') +let assert = require('assert'); -module.exports = function ({events}) { - assert.deepEqual( - events.getAll(), - [ - {name: 'a', type: 'boolean', doc: '\nSome doc\n'}, - {name: 'b', type: 'string', doc: undefined}, - {name: 'c', type: 'Event', doc: undefined} - ] - ); -} +module.exports = function ({ events }) { + assert.deepEqual(events.getAll(), [ + { name: 'a', type: 'boolean', doc: '\nSome doc\n' }, + { name: 'b', type: 'string', doc: undefined }, + { name: 'c', type: 'Event', doc: undefined } + ]); +}; diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/component-events-interface-string-literals/expected.js b/packages/svelte2tsx/test/svelte2tsx/samples/component-events-interface-string-literals/expected.js index b4385c1a1..4a3b0487e 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/component-events-interface-string-literals/expected.js +++ b/packages/svelte2tsx/test/svelte2tsx/samples/component-events-interface-string-literals/expected.js @@ -1,12 +1,9 @@ -let assert = require('assert') +let assert = require('assert'); -module.exports = function ({events}) { - assert.deepEqual( - events.getAll(), - [ - {name: 'a-b', type: 'boolean', doc: '\nSome doc\n'}, - {name: 'b', type: 'string', doc: undefined}, - {name: 'c', type: 'Event', doc: undefined} - ] - ); -} +module.exports = function ({ events }) { + assert.deepEqual(events.getAll(), [ + { name: 'a-b', type: 'boolean', doc: '\nSome doc\n' }, + { name: 'b', type: 'string', doc: undefined }, + { name: 'c', type: 'Event', doc: undefined } + ]); +}; diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/component-events-interface/expected.js b/packages/svelte2tsx/test/svelte2tsx/samples/component-events-interface/expected.js index 4432bacdc..ebece35b0 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/component-events-interface/expected.js +++ b/packages/svelte2tsx/test/svelte2tsx/samples/component-events-interface/expected.js @@ -1,12 +1,9 @@ -let assert = require('assert') +let assert = require('assert'); -module.exports = function ({events}) { - assert.deepEqual( - events.getAll(), - [ - {name: 'a', type: 'boolean', doc: '\nSome *doc*\n'}, - {name: 'b', type: 'string', doc: undefined}, - {name: 'c', type: 'Event', doc: undefined} - ] - ); -} +module.exports = function ({ events }) { + assert.deepEqual(events.getAll(), [ + { name: 'a', type: 'boolean', doc: '\nSome *doc*\n' }, + { name: 'b', type: 'string', doc: undefined }, + { name: 'c', type: 'Event', doc: undefined } + ]); +}; diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/event-dispatcher-events-alias/expected.js b/packages/svelte2tsx/test/svelte2tsx/samples/event-dispatcher-events-alias/expected.js index 645047a7e..997b066d3 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/event-dispatcher-events-alias/expected.js +++ b/packages/svelte2tsx/test/svelte2tsx/samples/event-dispatcher-events-alias/expected.js @@ -1,12 +1,9 @@ -let assert = require('assert') +let assert = require('assert'); -module.exports = function ({events}) { - assert.deepEqual( - events.getAll(), - [ - {name: 'btn', type: 'CustomEvent'}, - {name: 'hi', type: 'CustomEvent'}, - {name: 'bye', type: 'CustomEvent'}, - ] - ); -} +module.exports = function ({ events }) { + assert.deepEqual(events.getAll(), [ + { name: 'btn', type: 'CustomEvent' }, + { name: 'hi', type: 'CustomEvent' }, + { name: 'bye', type: 'CustomEvent' } + ]); +}; diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/event-dispatcher-events/expected.js b/packages/svelte2tsx/test/svelte2tsx/samples/event-dispatcher-events/expected.js index 645047a7e..997b066d3 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/event-dispatcher-events/expected.js +++ b/packages/svelte2tsx/test/svelte2tsx/samples/event-dispatcher-events/expected.js @@ -1,12 +1,9 @@ -let assert = require('assert') +let assert = require('assert'); -module.exports = function ({events}) { - assert.deepEqual( - events.getAll(), - [ - {name: 'btn', type: 'CustomEvent'}, - {name: 'hi', type: 'CustomEvent'}, - {name: 'bye', type: 'CustomEvent'}, - ] - ); -} +module.exports = function ({ events }) { + assert.deepEqual(events.getAll(), [ + { name: 'btn', type: 'CustomEvent' }, + { name: 'hi', type: 'CustomEvent' }, + { name: 'bye', type: 'CustomEvent' } + ]); +}; diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-event-dispatcher-typed/expected.js b/packages/svelte2tsx/test/svelte2tsx/samples/ts-event-dispatcher-typed/expected.js index a76bb956a..ae849edbc 100644 --- a/packages/svelte2tsx/test/svelte2tsx/samples/ts-event-dispatcher-typed/expected.js +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-event-dispatcher-typed/expected.js @@ -1,12 +1,9 @@ -let assert = require('assert') +let assert = require('assert'); -module.exports = function ({events}) { - assert.deepEqual( - events.getAll(), - [ - {name: 'hi', type: 'CustomEvent', doc: '\nA DOC\n'}, - {name: 'bye', type: 'CustomEvent', doc: '\nANOTHER DOC\n'}, - {name: 'btn', type: 'CustomEvent', doc: undefined} - ] - ); -} +module.exports = function ({ events }) { + assert.deepEqual(events.getAll(), [ + { name: 'hi', type: 'CustomEvent', doc: '\nA DOC\n' }, + { name: 'bye', type: 'CustomEvent', doc: '\nANOTHER DOC\n' }, + { name: 'btn', type: 'CustomEvent', doc: undefined } + ]); +}; diff --git a/packages/svelte2tsx/test/svelte2tsx/tsconfig.json b/packages/svelte2tsx/test/svelte2tsx/tsconfig.json index 7a18994b7..e3011b9b9 100644 --- a/packages/svelte2tsx/test/svelte2tsx/tsconfig.json +++ b/packages/svelte2tsx/test/svelte2tsx/tsconfig.json @@ -1,24 +1,16 @@ { "compilerOptions": { - "module": "ES6", - "noImplicitAny": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "sourceMap": true, - "noEmit": true, - "allowJs": true, - "jsxFactory": "h", - "jsx": "preserve" + "module": "ES6", + "noImplicitAny": true, + "noImplicitThis": true, + "noImplicitReturns": true, + "sourceMap": true, + "noEmit": true, + "allowJs": true, + "jsxFactory": "h", + "jsx": "preserve" }, - "files": [ - "../../svelte-shims.d.ts", - "../../svelte-jsx.d.ts", - ], - "include": [ - "/samples/**/*.tsx", - "../../*.d.ts" - ], - "exclude": [ - "node_modules" - ] - } \ No newline at end of file + "files": ["../../svelte-shims.d.ts", "../../svelte-jsx.d.ts"], + "include": ["/samples/**/*.tsx", "../../*.d.ts"], + "exclude": ["node_modules"] +} diff --git a/yarn.lock b/yarn.lock index 2d429b615..b845d1c1b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -531,13 +531,6 @@ astral-regex@^1.0.0: resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9" integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg== -axios@0.21.1: - version "0.21.1" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" - integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== - dependencies: - follow-redirects "^1.10.0" - balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" @@ -1200,11 +1193,6 @@ flatted@^2.0.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.2.tgz#4575b21e2bcee7434aa9be662f4b7b5f9c2b5138" integrity sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA== -follow-redirects@^1.10.0: - version "1.13.1" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.1.tgz#5f69b813376cee4fd0474a3aba835df04ab763b7" - integrity sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg== - fs-extra@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"