From 3d6e382b583646f047836b703a867c3b29ac91b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Seery?= Date: Wed, 27 Apr 2022 15:43:43 -0300 Subject: [PATCH] fix: replaced deprecated String.substr with String.slice (#3224) --- .changeset/eight-falcons-applaud.md | 5 +++++ packages/astro/src/core/routing/manifest/create.ts | 2 +- packages/astro/src/runtime/server/index.ts | 2 +- packages/astro/src/vite-plugin-astro/compile.ts | 2 +- packages/astro/src/vite-plugin-jsx/index.ts | 2 +- packages/astro/src/vite-plugin-markdown/index.ts | 2 +- packages/astro/test/astro-css-bundling.test.js | 2 +- 7 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .changeset/eight-falcons-applaud.md diff --git a/.changeset/eight-falcons-applaud.md b/.changeset/eight-falcons-applaud.md new file mode 100644 index 000000000..5896f028d --- /dev/null +++ b/.changeset/eight-falcons-applaud.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Replaced deprecated String.substr with String.slice diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index 9555d9753..3f29fddd3 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -92,7 +92,7 @@ function getGenerator(segments: RoutePart[][], addTrailingSlash: AstroConfig['tr const template = segments .map((segment) => { return segment[0].spread - ? `/:${segment[0].content.substr(3)}(.*)?` + ? `/:${segment[0].content.slice(3)}(.*)?` : '/' + segment .map((part) => { diff --git a/packages/astro/src/runtime/server/index.ts b/packages/astro/src/runtime/server/index.ts index 72b1d92c0..bc80e5cdb 100644 --- a/packages/astro/src/runtime/server/index.ts +++ b/packages/astro/src/runtime/server/index.ts @@ -367,7 +367,7 @@ export function createAstro( // When inside of project root, remove the leading path so you are // left with only `/src/images/tower.png` if (resolved.startsWith(projectRoot.pathname)) { - resolved = '/' + resolved.substr(projectRoot.pathname.length); + resolved = '/' + resolved.slice(projectRoot.pathname.length); } return resolved; }, diff --git a/packages/astro/src/vite-plugin-astro/compile.ts b/packages/astro/src/vite-plugin-astro/compile.ts index afa4cd637..f17695047 100644 --- a/packages/astro/src/vite-plugin-astro/compile.ts +++ b/packages/astro/src/vite-plugin-astro/compile.ts @@ -43,7 +43,7 @@ async function compile( ): Promise { const filenameURL = new URL(`file://${filename}`); const normalizedID = fileURLToPath(filenameURL); - const pathname = filenameURL.pathname.substr(config.root.pathname.length - 1); + const pathname = filenameURL.pathname.slice(config.root.pathname.length - 1); let rawCSSDeps = new Set(); let cssTransformError: Error | undefined; diff --git a/packages/astro/src/vite-plugin-jsx/index.ts b/packages/astro/src/vite-plugin-jsx/index.ts index dee04c0b1..004ae2eee 100644 --- a/packages/astro/src/vite-plugin-jsx/index.ts +++ b/packages/astro/src/vite-plugin-jsx/index.ts @@ -25,7 +25,7 @@ const IMPORT_STATEMENTS: Record = { const PREVENT_UNUSED_IMPORTS = ';;(React,Fragment,h);'; function getEsbuildLoader(fileExt: string): string { - return fileExt.substr(1); + return fileExt.slice(1); } function collectJSXRenderers(renderers: AstroRenderer[]): Map { diff --git a/packages/astro/src/vite-plugin-markdown/index.ts b/packages/astro/src/vite-plugin-markdown/index.ts index 105ff47e0..405fac742 100644 --- a/packages/astro/src/vite-plugin-markdown/index.ts +++ b/packages/astro/src/vite-plugin-markdown/index.ts @@ -151,7 +151,7 @@ ${setup}`.trim(); // Transform from `.astro` to valid `.ts` let { code: tsResult } = await transform(astroResult, { - pathname: fileUrl.pathname.substr(config.root.pathname.length - 1), + pathname: fileUrl.pathname.slice(config.root.pathname.length - 1), projectRoot: config.root.toString(), site: config.site ? new URL(config.base, config.site).toString() : undefined, sourcefile: id, diff --git a/packages/astro/test/astro-css-bundling.test.js b/packages/astro/test/astro-css-bundling.test.js index 7b3c70384..3170b796d 100644 --- a/packages/astro/test/astro-css-bundling.test.js +++ b/packages/astro/test/astro-css-bundling.test.js @@ -41,7 +41,7 @@ describe('CSS Bundling', function () { const link = $(`link[rel="stylesheet"][href^="${href}"]`); expect(link.length).to.be.greaterThanOrEqual(1); const outHref = link.attr('href'); - builtCSS.add(outHref.startsWith('../') ? outHref.substr(2) : outHref); + builtCSS.add(outHref.startsWith('../') ? outHref.slice(2) : outHref); } // test 2: assert old CSS was removed