fix: replaced deprecated String.substr with String.slice (#3224)

This commit is contained in:
Juan Martín Seery 2022-04-27 15:43:43 -03:00 committed by GitHub
parent 41c70ae503
commit 3d6e382b58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Replaced deprecated String.substr with String.slice

View file

@ -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) => {

View file

@ -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;
},

View file

@ -43,7 +43,7 @@ async function compile(
): Promise<CompileResult> {
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<string>();
let cssTransformError: Error | undefined;

View file

@ -25,7 +25,7 @@ const IMPORT_STATEMENTS: Record<string, string> = {
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<string, AstroRenderer> {

View file

@ -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,

View file

@ -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