Skip to content

Commit 0a308d3

Browse files
committed
refactor: simplify regex character classes using [\w-]
Simplifies character class [a-zA-Z0-9_-] to [\w-] in server-routes-preload-links.ts and chunk-optimizer.ts for cleaner, more readable regular expressions.
1 parent 1462eac commit 0a308d3

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

packages/angular/build/src/builders/application/chunk-optimizer.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,7 @@ export async function optimizeChunks(
301301
const result = await bundle.generate({
302302
minify: { mangle: false, compress: false },
303303
sourcemap,
304-
chunkFileNames: (chunkInfo) =>
305-
`${chunkInfo.name.replace(/-[a-zA-Z0-9_-]{8}$/, '')}-[hash].js`,
304+
chunkFileNames: (chunkInfo) => `${chunkInfo.name.replace(/-[\w-]{8}$/, '')}-[hash].js`,
306305
});
307306
optimizedOutput = result.output;
308307
} else {
@@ -323,8 +322,7 @@ export async function optimizeChunks(
323322
const result = await bundle.generate({
324323
compact: true,
325324
sourcemap,
326-
chunkFileNames: (chunkInfo) =>
327-
`${chunkInfo.name.replace(/-[a-zA-Z0-9_-]{8}$/, '')}-[hash].js`,
325+
chunkFileNames: (chunkInfo) => `${chunkInfo.name.replace(/-[\w-]{8}$/, '')}-[hash].js`,
328326
});
329327
optimizedOutput = result.output;
330328
}

tests/e2e/tests/build/server-rendering/server-routes-preload-links.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,36 +137,36 @@ const RESPONSE_EXPECTS: Record<
137137
}
138138
> = {
139139
'/': {
140-
matches: [/<link rel="modulepreload" href="(home-[a-zA-Z0-9_-]{8}\.js)">/],
140+
matches: [/<link rel="modulepreload" href="(home-[\w-]{8}\.js)">/],
141141
notMatches: [/ssg\-component/, /ssr/, /csr/, /cross-dep-/],
142142
},
143143
'/ssg': {
144144
matches: [
145-
/<link rel="modulepreload" href="(ssg\.routes-[a-zA-Z0-9_-]{8}\.js)">/,
146-
/<link rel="modulepreload" href="(ssg-component-[a-zA-Z0-9_-]{8}\.js)">/,
145+
/<link rel="modulepreload" href="(ssg\.routes-[\w-]{8}\.js)">/,
146+
/<link rel="modulepreload" href="(ssg-component-[\w-]{8}\.js)">/,
147147
],
148148
notMatches: [/home/, /ssr/, /csr/, /ssg-one/, /ssg-two/, /cross-dep-/],
149149
},
150150
'/ssg/one': {
151151
matches: [
152-
/<link rel="modulepreload" href="(ssg\.routes-[a-zA-Z0-9_-]{8}\.js)">/,
153-
/<link rel="modulepreload" href="(ssg-one-[a-zA-Z0-9_-]{8}\.js)">/,
152+
/<link rel="modulepreload" href="(ssg\.routes-[\w-]{8}\.js)">/,
153+
/<link rel="modulepreload" href="(ssg-one-[\w-]{8}\.js)">/,
154154
],
155155
notMatches: [/home/, /ssr/, /csr/, /ssg-two/, /ssg\-component/, /cross-dep-/],
156156
},
157157
'/ssg/two': {
158158
matches: [
159-
/<link rel="modulepreload" href="(ssg\.routes-[a-zA-Z0-9_-]{8}\.js)">/,
160-
/<link rel="modulepreload" href="(ssg-two-[a-zA-Z0-9_-]{8}\.js)">/,
159+
/<link rel="modulepreload" href="(ssg\.routes-[\w-]{8}\.js)">/,
160+
/<link rel="modulepreload" href="(ssg-two-[\w-]{8}\.js)">/,
161161
],
162162
notMatches: [/home/, /ssr/, /csr/, /ssg-one/, /ssg\-component/, /cross-dep-/],
163163
},
164164
'/ssr': {
165-
matches: [/<link rel="modulepreload" href="(ssr-[a-zA-Z0-9_-]{8}\.js)">/],
165+
matches: [/<link rel="modulepreload" href="(ssr-[\w-]{8}\.js)">/],
166166
notMatches: [/home/, /ssg\-component/, /csr/],
167167
},
168168
'/csr': {
169-
matches: [/<link rel="modulepreload" href="(csr-[a-zA-Z0-9_-]{8}\.js)">/],
169+
matches: [/<link rel="modulepreload" href="(csr-[\w-]{8}\.js)">/],
170170
notMatches: [/home/, /ssg\-component/, /ssr/, /cross-dep-/],
171171
},
172172
};

0 commit comments

Comments
 (0)