Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ import { mapObjWithRangeToOriginal, offsetAt, positionAt } from '../../../../lib
import { pathToUrl } from '../../../../utils';
import { SvelteDocument } from '../../SvelteDocument';
import ts from 'typescript';
// There are multiple estree-walker versions in the monorepo.
// The newer versions don't have start/end in their public interface,
// but the AST returned by svelte/compiler does.
// To get the Node type right in both dev and prod environment,
// declaring the Node type like this is necessary. Once
// all depend on the same estree(-walker) version, this should be revisited.
// estree does not have start/end in their public Node interface,
// but the AST returned by svelte/compiler does. Type as any as a workaround.
type Node = any;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { Position, SelectionRange } from 'vscode-languageserver';
import { isInTag, mapSelectionRangeToParent, offsetAt, toRange } from '../../../lib/documents';
import { SvelteDocument } from '../SvelteDocument';

// estree does not have start/end in their public Node interface,
// but the AST returned by svelte/compiler does. Type as any as a workaround.
type Node = any;

type OffsetRange = {
start: number;
end: number;
Expand All @@ -29,7 +33,7 @@ export async function getSelectionRange(svelteDoc: SvelteDocument, position: Pos
let result: SelectionRange | undefined;

walk(html, {
enter(node, parent) {
enter(node: Node, parent: Node) {
if (!parent) {
// keep looking
return;
Expand Down
12 changes: 6 additions & 6 deletions packages/svelte2tsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"magic-string": "^0.25.7",
"mocha": "^6.2.2",
"periscopic": "^2.0.2",
"rollup": "^1.12.0",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-delete": "^1.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-typescript": "^1.0.1",
"rollup": "^2.28.0",
"@rollup/plugin-commonjs": "^15.0.0",
"rollup-plugin-delete": "^2.0.0",
"@rollup/plugin-json": "^4.0.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"source-map": "^0.6.1",
"source-map-support": "^0.5.16",
"svelte": "3.28.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/svelte2tsx/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typescript from 'rollup-plugin-typescript';
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import json from 'rollup-plugin-json';
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import json from '@rollup/plugin-json';
import builtins from 'builtin-modules';

export default [
Expand All @@ -22,7 +22,7 @@ export default [
resolve({ browser: false, preferBuiltins: true }),
commonjs(),
json(),
typescript()
typescript({ include: ['src/**/*'] })
],
watch: {
clearScreen: false
Expand Down
12 changes: 6 additions & 6 deletions packages/svelte2tsx/rollup.config.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typescript from 'rollup-plugin-typescript';
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import json from 'rollup-plugin-json';
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import json from '@rollup/plugin-json';
import del from 'rollup-plugin-delete';
import builtins from 'builtin-modules';

Expand All @@ -18,7 +18,7 @@ export default [
resolve({ browser: false, preferBuiltins: true }),
commonjs(),
json(),
typescript()
typescript({ include: ['src/**/*'] })
],
external: [...builtins, 'typescript', 'svelte', 'svelte/compiler', 'magic-string']
},
Expand All @@ -34,7 +34,7 @@ export default [
resolve({ browser: false, preferBuiltins: true }),
commonjs(),
json(),
typescript()
typescript({ include: ['src/**/*'] })
],
external: [...builtins, 'typescript', 'svelte', 'svelte/compiler', 'magic-string']
}
Expand Down
22 changes: 22 additions & 0 deletions packages/svelte2tsx/src/estree.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { BaseNode } from 'estree';

// estree does not have start/end in their public Node interface,
// but the AST returned by svelte/compiler does.
// We add the those properties here and add Node as an interface
// to both estree and estree-walker.

declare module 'estree-walker' {
export interface Node extends BaseNode {
start: number;
end: number;
[propName: string]: any;
}
}

declare module 'estree' {
export interface BaseNode {
start: number;
end: number;
[propName: string]: any;
}
}
2 changes: 1 addition & 1 deletion packages/svelte2tsx/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"paths": {
"@/*": ["src/*"]
},
"include": [],
// "include" is set in rollup.config(.test).js
"exclude": ["node_modules"]
}
Loading