typescript-svelte-plugin 0.3.17 → 0.3.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.gatherDescendants = exports.offsetOfGeneratedComponentExport = exports.isGeneratedSvelteComponentName = exports.findNodeAtSpan = exports.get$storeOffsetOf$storeDeclaration = exports.isStoreVariableIn$storeDeclaration = exports.getConfigPathForProject = exports.replaceDeep = exports.isNoTextSpanInGeneratedCode = exports.isInGeneratedCode = exports.isNotNullOrUndefined = exports.ensureRealSvelteFilePath = exports.toRealSvelteFilePath = exports.isVirtualSvelteFilePath = exports.isSvelteFilePath = void 0;
3
+ exports.hasNodeModule = exports.findIdentifier = exports.gatherDescendants = exports.offsetOfGeneratedComponentExport = exports.isGeneratedSvelteComponentName = exports.isTopLevelExport = exports.findNodeAtPosition = exports.findNodeAtSpan = exports.get$storeOffsetOf$storeDeclaration = exports.isStoreVariableIn$storeDeclaration = exports.getConfigPathForProject = exports.replaceDeep = exports.isNoTextSpanInGeneratedCode = exports.isInGeneratedCode = exports.isNotNullOrUndefined = exports.ensureRealSvelteFilePath = exports.toRealSvelteFilePath = exports.isVirtualSvelteFilePath = exports.isSvelteFilePath = void 0;
4
4
  function isSvelteFilePath(filePath) {
5
5
  return filePath.endsWith('.svelte');
6
6
  }
@@ -107,6 +107,48 @@ function findNodeAtSpan(node, span, predicate) {
107
107
  }
108
108
  }
109
109
  exports.findNodeAtSpan = findNodeAtSpan;
110
+ /**
111
+ * Finds node somewhere at position.
112
+ */
113
+ function findNodeAtPosition(node, pos, predicate) {
114
+ for (const child of node.getChildren()) {
115
+ const childStart = child.getStart();
116
+ if (pos < childStart) {
117
+ return;
118
+ }
119
+ const childEnd = child.getEnd();
120
+ if (pos > childEnd) {
121
+ continue;
122
+ }
123
+ const foundInChildren = findNodeAtPosition(child, pos, predicate);
124
+ if (foundInChildren) {
125
+ return foundInChildren;
126
+ }
127
+ if (!predicate) {
128
+ return child;
129
+ }
130
+ if (predicate(child)) {
131
+ return child;
132
+ }
133
+ }
134
+ }
135
+ exports.findNodeAtPosition = findNodeAtPosition;
136
+ /**
137
+ * True if is `export const/let/function`
138
+ */
139
+ function isTopLevelExport(ts, node, source) {
140
+ var _a, _b;
141
+ return ((ts.isVariableStatement(node) && source.statements.includes(node)) ||
142
+ (ts.isIdentifier(node) &&
143
+ node.parent &&
144
+ ts.isVariableDeclaration(node.parent) &&
145
+ source.statements.includes((_b = (_a = node.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.parent)) ||
146
+ (ts.isIdentifier(node) &&
147
+ node.parent &&
148
+ ts.isFunctionDeclaration(node.parent) &&
149
+ source.statements.includes(node.parent)));
150
+ }
151
+ exports.isTopLevelExport = isTopLevelExport;
110
152
  const COMPONENT_SUFFIX = '__SvelteComponent_';
111
153
  function isGeneratedSvelteComponentName(className) {
112
154
  return className.endsWith(COMPONENT_SUFFIX);
@@ -128,4 +170,35 @@ function gatherDescendants(node, predicate, dest = []) {
128
170
  return dest;
129
171
  }
130
172
  exports.gatherDescendants = gatherDescendants;
173
+ function findIdentifier(ts, node) {
174
+ if (ts.isIdentifier(node)) {
175
+ return node;
176
+ }
177
+ if (ts.isFunctionDeclaration(node)) {
178
+ return node.name;
179
+ }
180
+ while (node) {
181
+ if (ts.isIdentifier(node)) {
182
+ return node;
183
+ }
184
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
185
+ return node.name;
186
+ }
187
+ node = node.parent;
188
+ }
189
+ }
190
+ exports.findIdentifier = findIdentifier;
191
+ function hasNodeModule(compilerOptions, module) {
192
+ try {
193
+ const hasModule = typeof compilerOptions.configFilePath !== 'string' ||
194
+ require.resolve(module, { paths: [compilerOptions.configFilePath] });
195
+ return hasModule;
196
+ }
197
+ catch (e) {
198
+ // If require.resolve fails, we end up here, which can be either because the package is not found,
199
+ // or (in case of things like SvelteKit) the package is found but the package.json is not exported.
200
+ return (e === null || e === void 0 ? void 0 : e.code) === 'ERR_PACKAGE_PATH_NOT_EXPORTED';
201
+ }
202
+ }
203
+ exports.hasNodeModule = hasNodeModule;
131
204
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-svelte-plugin",
3
- "version": "0.3.17",
3
+ "version": "0.3.19",
4
4
  "description": "A TypeScript Plugin providing Svelte intellisense",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {
@@ -24,6 +24,6 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@jridgewell/sourcemap-codec": "^1.4.14",
27
- "svelte2tsx": "~0.6.0"
27
+ "svelte2tsx": "~0.6.4"
28
28
  }
29
29
  }