Skip to content

Commit

Permalink
chore: use directive @ts-expect-error instead of @ts-ignore (#6429)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Mar 7, 2023
1 parent e1858e6 commit fe88f89
Show file tree
Hide file tree
Showing 21 changed files with 26 additions and 41 deletions.
4 changes: 2 additions & 2 deletions packages/astro/src/core/add/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import parser from '@babel/parser';
import traverse from '@babel/traverse';
import * as t from '@babel/types';

// @ts-ignore @babel/traverse isn't ESM and needs this trick
// @ts-expect-error @babel/traverse isn't ESM and needs this trick
export const visit = traverse.default as typeof traverse;
export { t };

export async function generate(ast: t.File) {
// @ts-ignore @babel/generator isn't ESM and needs this trick
// @ts-expect-error @babel/generator isn't ESM and needs this trick
const astToText = generator.default as typeof generator;
const { code } = astToText(ast);
return code;
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/build/plugins/plugin-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function vitePluginInternals(input: Set<string>, internals: BuildInternal
external.push('shiki');
}

// @ts-ignore
extra.ssr = {
external,
noExternal,
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/endpoint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function createAPIContext({
});
},
url: new URL(request.url),
// @ts-ignore
// @ts-expect-error
get clientAddress() {
if (!(clientAddressSymbol in request)) {
if (adapterName) {
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/src/core/render/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ export function createResult(args: CreateResultArgs): SSRResult {
const Astro: AstroGlobal = {
// @ts-expect-error
__proto__: astroGlobal,
// @ts-ignore
get clientAddress() {
if (!(clientAddressSymbol in request)) {
if (args.adapterName) {
Expand Down Expand Up @@ -221,7 +220,7 @@ export function createResult(args: CreateResultArgs): SSRResult {
writable: false,
// TODO: Remove this hole "Deno" logic once our plugin gets Deno support
value: async function (content: string, opts: MarkdownRenderingOptions) {
// @ts-ignore
// @ts-expect-error
if (typeof Deno !== 'undefined') {
throw new Error('Markdown is not supported in Deno SSR');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/jsx/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const renderer = {
jsxTransformOptions: async () => {
const {
default: { default: jsx },
// @ts-ignore
// @ts-expect-error
} = await import('@babel/plugin-transform-react-jsx');
const { default: astroJSX } = await import('./babel.js');
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/deno/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { SSRManifest } from 'astro';
import { App } from 'astro/app';

// @ts-ignore
// @ts-expect-error
import { fromFileUrl, serveFile, Server } from '@astrojs/deno/__deno_imports.js';

interface Options {
Expand All @@ -15,7 +15,7 @@ let _server: Server | undefined = undefined;
let _startPromise: Promise<void> | undefined = undefined;

async function* getPrerenderedFiles(clientRoot: URL): AsyncGenerator<URL> {
// @ts-ignore
// @ts-expect-error
for await (const ent of Deno.readDir(clientRoot)) {
if (ent.isDirectory) {
yield* getPrerenderedFiles(new URL(`./${ent.name}/`, clientRoot));
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/image/src/endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { APIRoute } from 'astro';
import mime from 'mime';
// @ts-ignore
// @ts-expect-error
import loader from 'virtual:image-loader';
import { etag } from './utils/etag.js';
import { isRemoteImage } from './utils/paths.js';
Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/image/src/lib/get-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export async function getImage(
let loader = globalThis.astroImage?.loader;

if (!loader) {
// @ts-ignore
// @ts-expect-error
const { default: mod } = await import('virtual:image-loader').catch(() => {
throw new Error(
'[@astrojs/image] Builtin image loader not found. (Did you remember to add the integration to your Astro config?)'
Expand All @@ -127,7 +127,7 @@ export async function getImage(
const attributes = await loader.getImageAttributes(resolved);

// `.env` must be optional to support running in environments outside of `vite` (such as `astro.config`)
// @ts-ignore
// @ts-expect-error
const isDev = import.meta.env?.DEV;
const isLocalImage = !isRemoteImage(resolved.src);

Expand Down
1 change: 0 additions & 1 deletion packages/integrations/image/src/loaders/squoosh.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-ignore
import { red } from 'kleur/colors';
import { error } from '../utils/logger.js';
import { metadata } from '../utils/metadata.js';
Expand Down
9 changes: 0 additions & 9 deletions packages/integrations/image/src/vendor/squoosh/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,46 +35,37 @@ export interface RotateOptions {

// MozJPEG
import type { MozJPEGModule as MozJPEGEncodeModule } from './mozjpeg/mozjpeg_enc'
// @ts-ignore
import mozEnc from './mozjpeg/mozjpeg_node_enc.js'
const mozEncWasm = new URL('./mozjpeg/mozjpeg_node_enc.wasm', getModuleURL(import.meta.url))
// @ts-ignore
import mozDec from './mozjpeg/mozjpeg_node_dec.js'
const mozDecWasm = new URL('./mozjpeg/mozjpeg_node_dec.wasm', getModuleURL(import.meta.url))

// WebP
import type { WebPModule as WebPEncodeModule } from './webp/webp_enc'
// @ts-ignore
import webpEnc from './webp/webp_node_enc.js'
const webpEncWasm = new URL('./webp/webp_node_enc.wasm', getModuleURL(import.meta.url))
// @ts-ignore
import webpDec from './webp/webp_node_dec.js'
const webpDecWasm = new URL('./webp/webp_node_dec.wasm', getModuleURL(import.meta.url))

// AVIF
import type { AVIFModule as AVIFEncodeModule } from './avif/avif_enc'
// @ts-ignore
import avifEnc from './avif/avif_node_enc.js'
const avifEncWasm = new URL('./avif/avif_node_enc.wasm', getModuleURL(import.meta.url))
// @ts-ignore
import avifDec from './avif/avif_node_dec.js'
const avifDecWasm = new URL('./avif/avif_node_dec.wasm', getModuleURL(import.meta.url))

// PNG
// @ts-ignore
import * as pngEncDec from './png/squoosh_png.js'
const pngEncDecWasm = new URL('./png/squoosh_png_bg.wasm', getModuleURL(import.meta.url))
const pngEncDecInit = () =>
pngEncDec.default(fsp.readFile(pathify(pngEncDecWasm.toString())))

// OxiPNG
// @ts-ignore
import * as oxipng from './png/squoosh_oxipng.js'
const oxipngWasm = new URL('./png/squoosh_oxipng_bg.wasm', getModuleURL(import.meta.url))
const oxipngInit = () => oxipng.default(fsp.readFile(pathify(oxipngWasm.toString())))

// Resize
// @ts-ignore
import * as resize from './resize/squoosh_resize.js'
const resizeWasm = new URL('./resize/squoosh_resize_bg.wasm', getModuleURL(import.meta.url))
const resizeInit = () => resize.default(fsp.readFile(pathify(resizeWasm.toString())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export async function processBuffer(
encoding: OutputFormat,
quality?: number
): Promise<Uint8Array> {
// @ts-ignore
const worker = await getWorker();

let imageData = await worker.dispatchJob({
Expand Down
1 change: 0 additions & 1 deletion packages/integrations/image/src/vendor/squoosh/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export async function decodeBuffer(
const encoder = supportedFormats[key]
const mod = await encoder.dec()
const rgba = mod.decode(new Uint8Array(buffer))
// @ts-ignore
return rgba
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @ts-ignore
// @ts-expect-error
import { runBuild } from './test-utils.ts';
// @ts-ignore
// @ts-expect-error
import { assertEquals, assert, DOMParser } from './deps.ts';

// @ts-ignore
// @ts-expect-error
Deno.env.set('SECRET_STUFF', 'secret');

// @ts-ignore
// @ts-expect-error
Deno.test({
// TODO: debug why build cannot be found in "await import"
ignore: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-ignore
// @ts-expect-error
import { runBuild } from './test-utils.ts';
// @ts-ignore
// @ts-expect-error
import { assertEquals } from './deps.ts';

// @ts-ignore
// @ts-expect-error
Deno.test({
name: 'Prerender',
async fn() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-ignore
// @ts-expect-error
import { runBuild } from './test-utils.ts';
// @ts-ignore
// @ts-expect-error
import { assertEquals, assert, DOMParser } from './deps.ts';

// @ts-ignore
// @ts-expect-error
Deno.test({
// TODO: debug why build cannot be found in "await import"
ignore: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-ignore
// @ts-expect-error
import { fromFileUrl, readableStreamFromReader } from './deps.ts';
const dir = new URL('./', import.meta.url);

export async function runBuild(fixturePath: string) {
// @ts-ignore
// @ts-expect-error
let proc = Deno.run({
cmd: ['node', '../../../../../../astro/astro.js', 'build', '--silent'],
cwd: fromFileUrl(new URL(fixturePath, dir)),
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/node/src/response-iterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function readerIterator<T>(reader: ReadableStreamDefaultReader<T>): AsyncIterabl

if (canUseAsyncIteratorSymbol) {
iterator[Symbol.asyncIterator] = function (): AsyncIterator<T> {
//@ts-ignore
//@ts-expect-error
return this;
};
}
Expand Down
1 change: 0 additions & 1 deletion packages/integrations/preact/src/client-dev.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-ignore
import 'preact/debug';
import clientFn from './client.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/markdown/remark/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function prefixError(err: any, prefix: string) {
const wrappedError = new Error(`${prefix}${err ? `: ${err}` : ''}`);
try {
wrappedError.stack = err.stack;
// @ts-ignore
// @ts-expect-error
wrappedError.cause = err;
} catch (error) {
// It's ok if we could not set the stack or cause - the message is the most important part
Expand Down
2 changes: 1 addition & 1 deletion packages/webapi/src/lib/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HTMLImageElement } from './HTMLImageElement'
import * as _ from './utils'

export function Image() {
// @ts-ignore
// @ts-expect-error
_.INTERNALS.set(this, {
attributes: {},
localName: 'img',
Expand Down
2 changes: 1 addition & 1 deletion packages/webapi/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const __object_isPrototypeOf = Function.call.bind(
/** Current high resolution millisecond timestamp. */
export const __performance_now = performance.now as () => number

// @ts-ignore
// @ts-expect-error
export const INTERNALS = new WeakMap<unknown, any>()

export const internalsOf = <T extends object>(
Expand Down

0 comments on commit fe88f89

Please sign in to comment.