@@ -4,42 +4,39 @@ import {CompileResult} from '../../../interfaces'
44
55import { JSAsset } from '../js-asset'
66
7+ import TypescriptAsset from 'parcel-bundler/src/assets/TypeScriptAsset'
8+
79export interface TranspileAsset extends JSAsset {
810 config : Promise < Configuration >
911
1012 transpile ( code : string ) : Promise < string >
1113}
1214
13- export function MakeTranspileAsset ( name : string , options : any ) : { new ( ) : TranspileAsset } {
14- const { parser} = options
15- const Asset = parser . findParser ( 'file.js' ) as typeof JSAsset
16-
17- return class TSAsset extends Asset {
18- public readonly config : Promise < Configuration >
19- private readonly transpiler : Promise < Transpiler >
15+ export class MakeTranspileAsset extends TypescriptAsset {
16+ public readonly config : Promise < Configuration >
17+ private readonly transpiler : Promise < Transpiler >
2018
21- constructor ( ) {
22- super ( name , options )
19+ constructor ( name : string , options : any ) {
20+ super ( name , options )
2321
24- this . config = loadConfiguration ( name , options . rootDir )
25- this . transpiler = this . config . then ( config =>
26- new Transpiler ( config )
27- )
28- }
22+ this . config = loadConfiguration ( name , options . rootDir )
23+ this . transpiler = this . config . then ( config =>
24+ new Transpiler ( config )
25+ )
26+ }
2927
30- public async parse ( code : string ) {
31- this . contents = await this . transpile ( code )
28+ public async parse ( code : string ) {
29+ this . contents = await this . transpile ( code )
3230
33- // Parse result as ast format through babylon
34- return super . parse ( this . contents )
35- }
31+ // Parse result as ast format through babylon
32+ return super . parse ( this . contents )
33+ }
3634
37- public async transpile ( code : string ) : Promise < string > {
38- const transpiler = await this . transpiler
39- const { sources} = transpiler . transpile ( code , this . name )
35+ public async transpile ( code : string ) : Promise < string > {
36+ const transpiler = await this . transpiler
37+ const { sources} = transpiler . transpile ( code , this . name )
4038
41- return processSourceMaps ( this , sources ) . js
42- }
39+ return processSourceMaps ( this , sources ) . js
4340 }
4441}
4542
0 commit comments