Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 2135b2f

Browse files
authored
Fix VS Code warnings (#1424)
1 parent efc29ed commit 2135b2f

File tree

8 files changed

+46
-48
lines changed

8 files changed

+46
-48
lines changed

runtime/src/app/app.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ stores.session.subscribe(async value => {
4545
if (!ready) return;
4646
session_dirty = true;
4747

48-
const target = select_target(new URL(location.href));
48+
const dest = select_target(new URL(location.href));
4949

5050
const token = current_token = {};
51-
const { redirect, props, branch } = await hydrate_target(target);
51+
const { redirect, props, branch } = await hydrate_target(dest);
5252
if (token !== current_token) return; // a secondary navigation happened while we were loading
5353

5454
if (redirect) {
5555
await goto(redirect.location, { replaceState: true });
5656
} else {
57-
await render(branch, props, target.page);
57+
await render(branch, props, dest.page);
5858
}
5959
});
6060

@@ -169,7 +169,7 @@ export function scroll_state() {
169169
};
170170
}
171171

172-
export async function navigate(target: Target, id: number, noscroll?: boolean, hash?: string): Promise<any> {
172+
export async function navigate(dest: Target, id: number, noscroll?: boolean, hash?: string): Promise<any> {
173173
if (id) {
174174
// popstate or initial navigation
175175
cid = id;
@@ -187,9 +187,9 @@ export async function navigate(target: Target, id: number, noscroll?: boolean, h
187187

188188
if (root_component) stores.preloading.set(true);
189189

190-
const loaded = prefetching && prefetching.href === target.href ?
190+
const loaded = prefetching && prefetching.href === dest.href ?
191191
prefetching.promise :
192-
hydrate_target(target);
192+
hydrate_target(dest);
193193

194194
prefetching = null;
195195

@@ -202,7 +202,7 @@ export async function navigate(target: Target, id: number, noscroll?: boolean, h
202202
await goto(redirect.location, { replaceState: true });
203203
} else {
204204
const { props, branch } = loaded_result;
205-
await render(branch, props, target.page);
205+
await render(branch, props, dest.page);
206206
}
207207
if (document.activeElement && (document.activeElement instanceof HTMLElement)) document.activeElement.blur();
208208

@@ -273,8 +273,8 @@ function part_changed(i, segment, match, stringified_query) {
273273
}
274274
}
275275

276-
export async function hydrate_target(target: Target): Promise<HydratedTarget> {
277-
const { route, page } = target;
276+
export async function hydrate_target(dest: Target): Promise<HydratedTarget> {
277+
const { route, page } = dest;
278278
const segments = page.path.split('/').filter(Boolean);
279279

280280
let redirect: Redirect = null;
@@ -339,7 +339,7 @@ export async function hydrate_target(target: Target): Promise<HydratedTarget> {
339339
host: page.host,
340340
path: page.path,
341341
query: page.query,
342-
params: part.params ? part.params(target.match) : {}
342+
params: part.params ? part.params(dest.match) : {}
343343
}, $session)
344344
: {};
345345
} else {

runtime/src/app/start/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ function handle_popstate(event: PopStateEvent) {
135135
if (target) {
136136
navigate(target, event.state.id);
137137
} else {
138-
location.href = location.href; // eslint-disable-line
138+
// eslint-disable-next-line
139+
location.href = location.href; // nosonar
139140
}
140141
} else {
141142
// hashchange

runtime/src/app/stores/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export function page_store<T>(value: T): PageStore<T> {
3636

3737
function subscribe(run: Subscriber<T>): Unsubscriber {
3838
let old_value;
39-
return store.subscribe((value) => {
40-
if (old_value === undefined || (ready && value !== old_value)) {
41-
run(old_value = value);
39+
return store.subscribe((new_value) => {
40+
if (old_value === undefined || (ready && new_value !== old_value)) {
41+
run(old_value = new_value);
4242
}
4343
});
4444
}

src/api/build.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ export async function build({
8989

9090
if (legacy) {
9191
process.env.SAPPER_LEGACY_BUILD = 'true';
92-
const { client } = await create_compilers(bundler, cwd, src, dest, false);
92+
const { client: legacy_client } = await create_compilers(bundler, cwd, src, dest, false);
9393

94-
const client_result = await client.compile();
94+
const legacy_client_result = await legacy_client.compile();
9595

9696
oncompile({
9797
type: 'client (legacy)',
98-
result: client_result
98+
result: legacy_client_result
9999
});
100100

101-
client_result.to_json(manifest_data, { src, routes, dest });
102-
build_info.legacy_assets = client_result.assets;
101+
legacy_client_result.to_json(manifest_data, { src, routes, dest });
102+
build_info.legacy_assets = legacy_client_result.assets;
103103
delete process.env.SAPPER_LEGACY_BUILD;
104104
}
105105

src/api/export.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as child_process from 'child_process';
22
import * as fs from 'fs';
33
import * as path from 'path';
4-
import * as url from 'url';
4+
import * as urllib from 'url';
55
import { promisify } from 'util';
66
import fetch from 'node-fetch';
77
import * as ports from 'port-authority';
@@ -35,14 +35,14 @@ type Ref = {
3535
as: string;
3636
};
3737

38-
type URL = url.UrlWithStringQuery;
38+
type URL = urllib.UrlWithStringQuery;
3939

4040
function resolve(from: string, to: string) {
41-
return url.parse(url.resolve(from, to));
41+
return urllib.parse(urllib.resolve(from, to));
4242
}
4343

44-
function cleanPath(path: string) {
45-
return path.replace(/^\/|\/$|\/*index(.html)*$|.html$/g, '');
44+
function cleanPath(p: string) {
45+
return p.replace(/^\/|\/$|\/*index(.html)*$|.html$/g, '');
4646
}
4747

4848
function get_href(attrs: string) {
@@ -118,10 +118,10 @@ async function _export({
118118
if (!root.href.endsWith('/')) root.href += '/';
119119

120120
const entryPoints = entry.split(' ').map(entryPoint => {
121-
const entry = resolve(origin, `${basepath}/${cleanPath(entryPoint)}`);
122-
if (!entry.href.endsWith('/')) entry.href += '/';
121+
const resolved = resolve(origin, `${basepath}/${cleanPath(entryPoint)}`);
122+
if (!resolved.href.endsWith('/')) resolved.href += '/';
123123

124-
return entry;
124+
return resolved;
125125
});
126126

127127
const proc = child_process.fork(path.resolve(`${build_dir}/server/server.js`), [], {
@@ -184,16 +184,16 @@ async function _export({
184184
addCallback(url);
185185
}
186186

187-
async function handleFetch(url: URL, { timeout, host, host_header }: FetchOpts) {
187+
async function handleFetch(url: URL, opts: FetchOpts) {
188188
const href = url.href;
189189
const timeout_deferred = new Deferred();
190190
const the_timeout = setTimeout(() => {
191191
timeout_deferred.reject(new Error(`Timed out waiting for ${href}`));
192-
}, timeout);
192+
}, opts.timeout);
193193

194194
const r = await Promise.race([
195195
fetch(href, {
196-
headers: { host: host_header || host },
196+
headers: { host: opts.host_header || opts.host },
197197
redirect: 'manual'
198198
}),
199199
timeout_deferred.promise
@@ -209,11 +209,10 @@ async function _export({
209209

210210
async function handleResponse(fetched: Promise<FetchRet>, fetchOpts: FetchOpts) {
211211
const { response, url } = await fetched;
212-
const { protocol, host, root } = fetchOpts;
213212
let pathname = url.pathname;
214213

215214
if (pathname !== '/service-worker-index.html') {
216-
pathname = pathname.replace(root.pathname, '') || '/';
215+
pathname = pathname.replace(fetchOpts.root.pathname, '') || '/';
217216
}
218217

219218
let type = response.headers.get('Content-Type');
@@ -261,10 +260,9 @@ async function _export({
261260
hrefs = hrefs.filter(Boolean);
262261

263262
for (const href of hrefs) {
264-
const url = resolve(base.href, href);
265-
266-
if (url.protocol === protocol && url.host === host) {
267-
handle(url, fetchOpts, queue.add);
263+
const dest = resolve(base.href, href);
264+
if (dest.protocol === fetchOpts.protocol && dest.host === fetchOpts.host) {
265+
handle(dest, fetchOpts, queue.add);
268266
}
269267
}
270268
}
@@ -277,13 +275,13 @@ async function _export({
277275
type = 'text/html';
278276
body = `<script>window.location.href = "${location.replace(origin, '')}"</script>`;
279277

280-
handle(resolve(root.href, location), fetchOpts, queue.add);
278+
handle(resolve(fetchOpts.root.href, location), fetchOpts, queue.add);
281279
}
282280

283281
return save(pathname, response.status, type, body);
284282
}
285283

286-
const fetchOpts = {
284+
const queueFetchOpts = {
287285
timeout: timeout === false ? 0 : timeout,
288286
host,
289287
host_header,
@@ -295,7 +293,7 @@ async function _export({
295293
concurrent,
296294
seen,
297295
saved,
298-
fetchOpts,
296+
fetchOpts: queueFetchOpts,
299297
handleFetch,
300298
handleResponse,
301299
callbacks: {
@@ -320,12 +318,12 @@ async function _export({
320318
oninfo({
321319
message: `Crawling ${entryPoint.href}`
322320
});
323-
handle(entryPoint, fetchOpts, queue.add);
321+
handle(entryPoint, queueFetchOpts, queue.add);
324322
}
325323

326324
if (has_serviceworker) {
327325
const workerUrl = resolve(root.href, 'service-worker-index.html');
328-
handle(workerUrl, fetchOpts, queue.add);
326+
handle(workerUrl, queueFetchOpts, queue.add);
329327
}
330328
} catch (err) {
331329
proc.kill();

src/api/utils/export_queue.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ function exportQueue({ concurrent, handleFetch, handleResponse, fetchOpts, callb
8888

8989
// move urls from urls queue and into fetching queue until fetching queue is full
9090
while (fetching.length < concurrent && urls.length) {
91-
const url = urls.shift();
92-
addToQueue(handleFetch(url, fetchOpts), fetching);
91+
addToQueue(handleFetch(urls.shift(), fetchOpts), fetching);
9392
}
9493

9594
if (urls.length === 0 && saving.length === 0 && fetching.length === 0) {
@@ -100,8 +99,8 @@ function exportQueue({ concurrent, handleFetch, handleResponse, fetchOpts, callb
10099
}
101100

102101
return {
103-
add: (url: URL) => {
104-
urls.push(url);
102+
add: (u: URL) => {
103+
urls.push(u);
105104
return processQueue();
106105
},
107106
addSave: (p: Promise<any>) => {

src/core/create_compilers/RollupCompiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export default class RollupCompiler {
5151
});
5252

5353
mod.onwarn = (warning: any) => {
54-
onwarn(warning, (warning: any) => {
55-
this.warnings.push(warning);
54+
onwarn(warning, (warn: any) => {
55+
this.warnings.push(warn);
5656
});
5757
};
5858

src/core/create_compilers/RollupResult.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class RollupResult implements CompileResult {
5050
} else {
5151
for (const name in compiler.input) {
5252
const file = compiler.input[name];
53-
const chunk = compiler.chunks.find(chunk => file in chunk.modules);
53+
const chunk = compiler.chunks.find(chnk => file in chnk.modules);
5454
if (chunk) this.assets[name] = chunk.fileName;
5555
}
5656
}

0 commit comments

Comments
 (0)