@@ -21,8 +21,8 @@ import { cache } from './cache.ts'
21
21
import type { RequiredConfig } from './config.ts'
22
22
import { defaultConfig , fixConfigAndImportMap , getDefaultImportMap , loadConfig , loadImportMap } from './config.ts'
23
23
import {
24
- checkAlephDev , checkDenoVersion , clearBuildCache , computeHash , findFile ,
25
- getAlephPkgUri , getSourceType , isLocalUrl , moduleExclude , toLocalPath , toRelativePath
24
+ checkAlephDev , checkDenoVersion , clearBuildCache , computeHash , decoder , encoder , findFile ,
25
+ getAlephPkgUri , getSourceType , isLocalUrl , moduleExclude , toLocalPath , toRelativePath ,
26
26
} from './helper.ts'
27
27
import { getContentType } from './mime.ts'
28
28
import { buildHtml , Renderer } from './renderer.ts'
@@ -798,7 +798,7 @@ export class Aleph implements IAleph {
798
798
if ( sourceType === SourceType . Unknown || sourceType === SourceType . CSS ) {
799
799
return [ ]
800
800
}
801
- const code = ( new TextDecoder ) . decode ( content )
801
+ const code = decoder . decode ( content )
802
802
const names = await parseExportNames ( specifier , code , { sourceType } )
803
803
return ( await Promise . all ( names . map ( async name => {
804
804
if ( name . startsWith ( '{' ) && name . endsWith ( '}' ) ) {
@@ -827,7 +827,7 @@ export class Aleph implements IAleph {
827
827
if ( type !== 'css' ) {
828
828
for ( const { test, load } of this . #loadListeners) {
829
829
if ( test . test ( `.${ type } ` ) ) {
830
- const { code, type : codeType } = await load ( { specifier : key , data : ( new TextEncoder ) . encode ( tpl ) } )
830
+ const { code, type : codeType } = await load ( { specifier : key , data : encoder . encode ( tpl ) } )
831
831
if ( codeType === 'css' ) {
832
832
type = 'css'
833
833
tpl = code
@@ -836,7 +836,7 @@ export class Aleph implements IAleph {
836
836
}
837
837
}
838
838
}
839
- const { code } = await cssLoader ( { specifier : key , data : ( new TextEncoder ) . encode ( tpl ) } , this )
839
+ const { code } = await cssLoader ( { specifier : key , data : encoder . encode ( tpl ) } , this )
840
840
return code
841
841
} ,
842
842
isDev : this . isDev ,
@@ -969,7 +969,7 @@ export class Aleph implements IAleph {
969
969
return module . jsBuffer
970
970
}
971
971
972
- let code = new TextDecoder ( ) . decode ( module . jsBuffer )
972
+ let code = decoder . decode ( module . jsBuffer )
973
973
if ( module . denoHooks ?. length || module . ssrPropsFn || module . ssgPathsFn ) {
974
974
if ( 'csrCode' in module ) {
975
975
code = ( module as any ) . csrCode
@@ -992,7 +992,7 @@ export class Aleph implements IAleph {
992
992
// todo: merge source map
993
993
}
994
994
}
995
- return new TextEncoder ( ) . encode ( [
995
+ return encoder . encode ( [
996
996
`import.meta.hot = $createHotContext(${ JSON . stringify ( specifier ) } );` ,
997
997
'' ,
998
998
code ,
@@ -1075,7 +1075,7 @@ export class Aleph implements IAleph {
1075
1075
const source = await this . fetchModule ( specifier )
1076
1076
sourceType = getSourceType ( specifier , source . contentType || undefined )
1077
1077
if ( sourceType !== SourceType . Unknown ) {
1078
- sourceCode = ( new TextDecoder ) . decode ( source . content )
1078
+ sourceCode = decoder . decode ( source . content )
1079
1079
}
1080
1080
}
1081
1081
@@ -1234,7 +1234,6 @@ export class Aleph implements IAleph {
1234
1234
}
1235
1235
1236
1236
const ms = new Measure ( )
1237
- const encoder = new TextEncoder ( )
1238
1237
const { code, deps = [ ] , denoHooks, ssrPropsFn, ssgPathsFn, starExports, jsxStaticClassNames, map } = await transform ( specifier , source . code , {
1239
1238
...this . commonCompilerOptions ,
1240
1239
sourceMap : this . isDev ,
@@ -1405,7 +1404,7 @@ export class Aleph implements IAleph {
1405
1404
1406
1405
/** replace dep hash in the `jsBuffer` and remove `csrCode` cache if it exits */
1407
1406
private async replaceDepHash ( module : Module , hashLoc : number , hash : string ) {
1408
- const hashData = ( new TextEncoder ( ) ) . encode ( hash . substr ( 0 , 6 ) )
1407
+ const hashData = encoder . encode ( hash . substr ( 0 , 6 ) )
1409
1408
const jsBuffer = await this . getModuleJS ( module )
1410
1409
if ( jsBuffer && ! equals ( hashData , jsBuffer . slice ( hashLoc , hashLoc + 6 ) ) ) {
1411
1410
copy ( hashData , jsBuffer , hashLoc )
0 commit comments