Skip to content

Commit

Permalink
fix: replace deprecated .substr with .substring
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Feb 20, 2022
1 parent 884d34d commit b4df2b4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/Chunk.ts
Expand Up @@ -450,7 +450,7 @@ export default class Chunk {
const extension = extname(sanitizedId);
const fileName = renderNamePattern(pattern, 'output.entryFileNames', {
assetExtname: () => (NON_ASSET_EXTENSIONS.includes(extension) ? '' : extension),
ext: () => extension.substr(1),
ext: () => extension.substring(1),
extname: () => extension,
format: () => options.format as string,
name: () => this.getChunkName()
Expand All @@ -466,7 +466,7 @@ export default class Chunk {
const extension = extname(sanitizedId);
const fileName = renderNamePattern(pattern, 'output.entryFileNames', {
assetExtname: () => (NON_ASSET_EXTENSIONS.includes(extension) ? '' : extension),
ext: () => extension.substr(1),
ext: () => extension.substring(1),
extname: () => extension,
format: () => options.format as string,
name: () => getAliasName(sanitizedId)
Expand Down Expand Up @@ -1161,7 +1161,7 @@ export default class Chunk {
let imported: string;
let needsLiveBinding = false;
if (exportName[0] === '*') {
const id = exportName.substr(1);
const id = exportName.substring(1);
if (interop(id) === 'defaultOnly') {
this.inputOptions.onwarn(errUnexpectedNamespaceReexport(id));
}
Expand Down
8 changes: 4 additions & 4 deletions src/ast/nodes/MetaProperty.ts
Expand Up @@ -43,7 +43,7 @@ export default class MetaProperty extends NodeBase {
getReferencedFileName(outputPluginDriver: PluginDriver): string | null {
const metaProperty = this.metaProperty as string | null;
if (metaProperty && metaProperty.startsWith(FILE_PREFIX)) {
return outputPluginDriver.getFileName(metaProperty.substr(FILE_PREFIX.length));
return outputPluginDriver.getFileName(metaProperty.substring(FILE_PREFIX.length));
}
return null;
}
Expand Down Expand Up @@ -91,23 +91,23 @@ export default class MetaProperty extends NodeBase {
let chunkReferenceId: string | null = null;
let fileName: string;
if (metaProperty.startsWith(FILE_PREFIX)) {
referenceId = metaProperty.substr(FILE_PREFIX.length);
referenceId = metaProperty.substring(FILE_PREFIX.length);
fileName = outputPluginDriver.getFileName(referenceId);
} else if (metaProperty.startsWith(ASSET_PREFIX)) {
warnDeprecation(
`Using the "${ASSET_PREFIX}" prefix to reference files is deprecated. Use the "${FILE_PREFIX}" prefix instead.`,
true,
this.context.options
);
assetReferenceId = metaProperty.substr(ASSET_PREFIX.length);
assetReferenceId = metaProperty.substring(ASSET_PREFIX.length);
fileName = outputPluginDriver.getFileName(assetReferenceId);
} else {
warnDeprecation(
`Using the "${CHUNK_PREFIX}" prefix to reference files is deprecated. Use the "${FILE_PREFIX}" prefix instead.`,
true,
this.context.options
);
chunkReferenceId = metaProperty.substr(CHUNK_PREFIX.length);
chunkReferenceId = metaProperty.substring(CHUNK_PREFIX.length);
fileName = outputPluginDriver.getFileName(chunkReferenceId);
}
const relativePath = normalize(relative(dirname(chunkId), fileName));
Expand Down
15 changes: 8 additions & 7 deletions src/utils/FileEmitter.ts
Expand Up @@ -42,16 +42,17 @@ function generateAssetFileName(
: outputOptions.assetFileNames,
'output.assetFileNames',
{
ext: () => extname(emittedName).substr(1),
ext: () => extname(emittedName).substring(1),
extname: () => extname(emittedName),
hash() {
const hash = createHash();
hash.update(emittedName);
hash.update(':');
hash.update(source);
return hash.digest('hex').substr(0, 8);
return createHash()
.update(emittedName)
.update(':')
.update(source)
.digest('hex')
.substring(0, 8);
},
name: () => emittedName.substr(0, emittedName.length - extname(emittedName).length)
name: () => emittedName.substring(0, emittedName.length - extname(emittedName).length)
}
),
bundle
Expand Down
2 changes: 1 addition & 1 deletion src/utils/relativeId.ts
Expand Up @@ -2,7 +2,7 @@ import { basename, extname, isAbsolute, relative, resolve } from './path';

export function getAliasName(id: string): string {
const base = basename(id);
return base.substr(0, base.length - extname(id).length);
return base.substring(0, base.length - extname(id).length);
}

export default function relativeId(id: string): string {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/renderNamePattern.ts
Expand Up @@ -35,7 +35,7 @@ export function makeUnique(name: string, existingNames: Record<string, unknown>)
if (!existingNamesLowercase.has(name.toLocaleLowerCase())) return name;

const ext = extname(name);
name = name.substr(0, name.length - ext.length);
name = name.substring(0, name.length - ext.length);
let uniqueName: string,
uniqueIndex = 1;
while (existingNamesLowercase.has((uniqueName = name + ++uniqueIndex + ext).toLowerCase()));
Expand Down

0 comments on commit b4df2b4

Please sign in to comment.