Skip to content

Commit eeca1ff

Browse files
committed
Fix forking server
1 parent 2105046 commit eeca1ff

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

src/frontend/assets/classes/transpile.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,39 @@ import {CompileResult} from '../../../interfaces'
44

55
import {JSAsset} from '../js-asset'
66

7+
import TypescriptAsset from 'parcel-bundler/src/assets/TypeScriptAsset'
8+
79
export 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

src/frontend/assets/forked.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {IPCClient} from '../../backend/worker/client'
22
import {MakeTranspileAsset} from './classes/transpile'
33

44
export = function(name: string, options: any): any {
5-
return new (class extends MakeTranspileAsset(name, options) {
5+
return new (class extends MakeTranspileAsset {
66
public async transpile(code: string) {
77
const config = await this.config
88
const reportErrors = !config.typescript.options.noEmitOnError
@@ -25,5 +25,5 @@ export = function(name: string, options: any): any {
2525

2626
return super.transpile(code)
2727
}
28-
})()
28+
})(name, options)
2929
}

src/frontend/assets/transpile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {MakeTranspileAsset, TranspileAsset} from './classes/transpile'
22

33
export = function(name: string, options: any): TranspileAsset {
4-
return new (MakeTranspileAsset(name, options))()
4+
return new MakeTranspileAsset(name, options)
55
}

0 commit comments

Comments
 (0)